I want to create a set of database seed classes specifically for adding data for test cases I'm writing.
My plan was to put them in the folder:
app/database/seeds/testData/
and then call the seeder via the command:
php artisan db:seed --class="testData/myTestSeeder"
But I get a "class does not exist" error.
Is it possible to call database seeders that live in a subfolder in seeds? I don't see an explicit "yes" in the docs, but I don't see an explicit "no" either.
The db:seed command is used to add records to a database automatically using a Seeder ( Illuminate\Database\Seeder ) class to generate or provide the records.
A seeder is a special class used to generate and insert sample data (seeds) in a database.
You shouldn't need to edit your classmap
on your project, just make sure to run
composer dump-autoload
after moving your class to a subfolder.
Once you've done that, run this (no need to mention testData here)
php artisan db:seed --class="myTestSeeder"
You need to tell the autoloader how to load your new class. This is relatively simple; add the following to your composer.json in the classmap
property:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/database/seeds/testData" // <-- Add this
]
},
After that, run composer dump-autoload
and your seed file should now be loaded successfully.
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