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"
}
orecrush said:
You tried composer dumpautoload I assume?
yes
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']);
});
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community