Support the ongoing development of Laravel.io →
posted 10 years ago
Packages

Hi,

I've setup a fresh laravel 4.2 install, created a package using the --ressources option (exemple: toto/tata), and added a "models" directory into the src folder and a Role.php class in it :

<?php

class Role extends Eloquent {
 protected $fillable = ['name'];

}

However when I try to call the model within my package routes (toto/tata/src/routes.php) class doesn't seems to load, when I try :

<?php
Route::get('toto', function()
{
 $member = Role::create(['name' => 'member']);
});

I got a "Class 'Role' not found" message

my package composer.json is :

{
    "name": "alakees/cms",
    "description": "",
    "authors": [
        {
            "name": "Emmanuel Dubuc",
            "email": "edubuc@alakees.com"
        }
    ],
    "require": {
        "php": ">=5.4.0",
        "illuminate/support": "4.2.*"
    },
    "autoload": {
        "classmap": [
            "src/migrations"
        ],
        "psr-0": {
            "Alakees\\Cms\\": "src/"
        }
    },
    "minimum-stability": "stable"
}
Last updated 3 years ago.
0

You tried composer dumpautoload I assume?

Last updated 3 years ago.
0

orecrush said:

You tried composer dumpautoload I assume?

yes

Last updated 3 years ago.
0

You have no namespaces setup in your Role.php

Per your PSR-0 structure, and as you said you have a "models" dir:

// Role.php
<?php namespace Alakees\Cms\Models;

class Role extends Eloquent {
 protected $fillable = ['name'];

}

Then you can call this Role using the namespace:

<?php
Route::get('toto', function()
{
 $member = \Alakees\Cms\Models\Role::create(['name' => 'member']);
});
Last updated 3 years ago.
0

Thanks for your answer, in fact my error, on top of the missing namespace, was that my "models" directory was in alakees/cms/src. I moved it instead to alakees/cms/src/Alakees/Cms and now it's fine

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

edubuc edubuc Joined 17 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.