A Laravel Seeder is a tool that populates the database with test or initial data. Seeders are commonly used to set up default application data, such as admin users, roles, or predefined settings.
Seeders were introduced in Laravel to simplify database initialization and testing workflows by automating data population.
Create a seeder:
php artisan make:seeder UserSeeder
In the seeder class:
use Illuminate\Database\Seeder;
use App\Models\User;
class UserSeeder extends Seeder
{
public function run()
{
User::factory()->count(10)->create();
}
}
Run the seeder:
php artisan db:seed --class=UserSeeder
Seeders automate data population, ensuring a consistent and efficient setup process for Laravel applications.