I follow the docs: http://laravel.com/docs/master/migrations#database-seeding
I placed UserTableSeeder
file near DatabaseSeeder
. In resources/database/seeds/
folder.
These files are without namespaces (only classes in app/
are namespaced).
Of course there is an exception: exception 'ReflectionException' with message 'Class UserTableSeeder does not exist'
What is the best way to solve this problem?
Writing SeedersA seeder class only contains one method by default: run . This method is called when the db:seed Artisan command is executed. Within the run method, you may insert data into your database however you wish. You may use the query builder to manually insert data or you may use Eloquent model factories.
Database seeder is used to populate tables with data. Model factories is a convenient centralized place to define how your models should be populated with fake data.
Once you're done writing the seeders, use the db:seed command. This will run DatabaseSeeder 's run function. You may also specify to run a specific seeder class to run individually using the --class option.
The default Laravel 5 project has a classmap defined in its composer.json
:
{
// ...
"autoload": {
"classmap": [
"database"
],
// ...
}
}
Run composer dump
every time you add or remove a class on your database
directory to update the Composer autoloader
Reference: https://github.com/laravel/laravel/blob/develop/composer.json
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