Laravel 9 db seed run specific seeder file
Laravel is a very popular php framework. It provides the feature of seeder to seed the database with sample data for testing purposes or with some ready to use data.
In this tutorial, we will know how to run a specific seeder instead of all seeders at once. As a developer database seeders are very helpful to feed the sample data to the database and test the application smoothly. It eliminates the need of manual data for testing the laravel project.
How to run a specific seeder in laravel 9?
If you are already familiar with laravel 9 database seeders then you might know that we create the seeder classes to run the seeder. So, to run a specific seeder we need to mention the class in the seeder command as given below:
php artisan db:seed php artisan db:seed --class=UserSeeder
Sometimes you might need to run cache
clear commands or composer dump-autoload
command, if your seeder class is discovered yet. In this case you might see the error.
“Target class [Database\Seeders\YourSeederClass] does not exist.”
Run a seeder with migration command
There is another thing which is important to know. If you are refreshing the complete database with migrate:fresh
command and then running the specific seeder class, here you can do all of this with just a single command.
php artisan migrate:fresh --seed php artisan migrate:fresh --seed --seeder=UserSeeder
That’s it. How to run a specific seeder in laravel 9. Hope it will help you.