Laravel

Laravel 9 db seed run specific seeder file

Share your learning

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.

Satpal

Recent Posts

How to Switch PHP Versions in XAMPP Easily: Managing Multiple PHP Versions on Ubuntu

Today we are going to learn about managing multiple PHP versions on ubuntu with xampp.…

1 year ago

How to Use Coding to Improve Your Website’s SEO Ranking?

Let's understand about how to use coding to improve your website's SEO. In today’s computerized…

1 year ago

Most Important Linux Commands for Web Developers

Let's understand the most important linux commands for web developers. Linux, as an open-source and…

1 year ago

Top 75+ Laravel Interview Questions Asked by Top MNCs

Today we are going to discuss top 75+ Laravel interview questions asked by top MNCs.Laravel,…

1 year ago

Mailtrap Integration for Email Testing with Laravel 10

Today we will discuss about the Mailtrap integration with laravel 10 .Sending and receiving emails…

1 year ago

Firebase Cloud Messaging (FCM) with Ionic 6: Push Notifications

Today we are going to integrate FCM (Firebase Cloud Messaging) push notifications with ionic application.Firebase…

1 year ago