Laravel 5 Do not find bright models

I am new to Laravel and am having trouble loading my models to seed a database. I tried both the Laravel 4 method for the .json composer and the Laravel 5 PSR-4.

DatabaseSeeder.php

use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model; class DatabaseSeeder extends Seeder { /** * Run the 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

This is in the application \ Models at the moment, but I tried them in the application next to Users.php

 namespace App\Models; use Illuminate\Database\Eloquent\Model as Eloquent; class Client extends \Eloquent { proteced $fillable = ['id', 'name', 'email', 'created_at', 'updated_at']; } 

module.php

 namespace App\Models; use Illuminate\Database\Eloquent\Model as Eloquent; class Module extends \Eloquent { proteced $fillable = ['id', 'name', 'created_at', 'updated_at']; } 

ModuleConnection.php

 namespace App\Models; use Illuminate\Database\Eloquent\Model as Eloquent; class ModuleConnection extends \Eloquent { proteced $fillable = ['id', 'clientid', 'moduleid', 'apiconn', 'created_at', 'updated_at']; } 

Error

This is when I run php artisan db: seed

 [Symfony\Component\Debug\Exception\FatalErrorException] Class 'App\Models\Client' not found 

I'm sure this is something stupid, I disappeared as a newbie! Thanks!

+6
source share
1 answer

First, you may have to distribute Eloquent, not \ Eloquent. When you add \ to your use, you tell PHP to find Eloquent in your root namespace. So:

 namespace App\Models; use Illuminate\Database\Eloquent\Model as Eloquent; class Module extends Eloquent { proteced $fillable = ['id', 'name', 'created_at', 'updated_at']; } 

Secondly, there is no need to do composer dumpautoload , because your application namespace was included in the Laravel configuration:

 "autoload": { ... "psr-4": { "App\\": "app/" } }, 

This tells the autoloader to look for your classes with names in the app/ path.

The thing you should check is if the Client.php file is in the folder:

 app/Models/Client.php 

And called as it is. Other than that, I don't see a problem in your code.

+1
source

Source: https://habr.com/ru/post/986238/


All Articles