php - Laravel 5 Not Finding Eloquent Models -
i'm brand new laravel , having trouble loading models in order seed database. have tried both laravel 4 method of composer.json , laravel 5 psr-4.
databaseseeder.php
use illuminate\database\seeder; use illuminate\database\eloquent\model; class databaseseeder extends seeder { /** * run database seeds. * * @return void */ public function run() { \app\models\client::truncate(); \app\models\module::truncate(); \app\models\moduleconnection::truncate(); model::unguard(); $this->call('clientstableseeder'); $this->call('modulestableseeder'); $this->call('conncetionstableseeder'); } }
client.php
these in app\models @ moment, have tried them in app next users.php
namespace app\models; use illuminate\database\eloquent\model eloquent; class client extends \eloquent { proteced $fillable = ['id', 'name', 'email', 'created_at', 'updated_at']; }
module.php
namespace app\models; use illuminate\database\eloquent\model eloquent; class module extends \eloquent { proteced $fillable = ['id', 'name', 'created_at', 'updated_at']; }
moduleconnection.php
namespace app\models; use illuminate\database\eloquent\model eloquent; class moduleconnection extends \eloquent { proteced $fillable = ['id', 'clientid', 'moduleid', 'apiconn', 'created_at', 'updated_at']; }
the error
this when run php artisan db:seed
[symfony\component\debug\exception\fatalerrorexception] class 'app\models\client' not found
i'm sure it's stupid i'm missing beginner! thanks!
first, have extend eloquent , not \eloquent. when add \ on usage, telling php find eloquent in root namespace. so:
namespace app\models; use illuminate\database\eloquent\model eloquent; class module extends eloquent { proteced $fillable = ['id', 'name', 'created_at', 'updated_at']; }
second, there's no need composer dumpautoload
because app namespace included laravel instalation:
"autoload": { ... "psr-4": { "app\\": "app/" } },
this telling autoloader search namespaced classes in app/
path.
the thing have check if file client.php in folder:
app/models/client.php
and named is. other don't see problem in code.
Comments
Post a Comment