I'm brand new to Laravel and am having trouble loading my models in order to seed the database. I have tried both the Laravel 4 method of composer.json and the Laravel 5 PSR-4.
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');
}
}
These are in app\Models at the moment, but I have tried them in app 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'];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Module extends \Eloquent {
proteced $fillable = ['id', 'name', 'created_at', 'updated_at'];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class ModuleConnection extends \Eloquent {
proteced $fillable = ['id', 'clientid', 'moduleid', 'apiconn', 'created_at', 'updated_at'];
}
This is when I run php artisan db:seed
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'App\Models\Client' not found
I'm sure it's something stupid I'm missing as a beginner! Thanks!
First, you probably have to extend Eloquent and not \Eloquent. When you add a \ on your usage, you are telling PHP to find an Eloquent in its 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'];
}
Second, there's no need to do a composer dumpautoload
because your App namespace was included by your Laravel instalation:
"autoload": {
...
"psr-4": {
"App\\": "app/"
}
},
This is telling the autoloader to search for your namespaced classes in the app/
path.
The thing you have to check is if the file Client.php is in the folder:
app/Models/Client.php
And named as is. Other than that I don't see a problem in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With