Google News
logo
Laravel - Interview Questions
What are seeders in Laravel?
Seeders in Laravel are used to put data in the database tables automatically. After running migrations to create the tables, we can run `php artisan db:seed` to run the seeder to populate the database tables.
 
We can create a new Seeder using the below artisan command:
php artisan make:seeder [className]
It will create a new Seeder like below:
<?php

use App\Models\Auth\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;

class UserTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run()
    {
        factory(User::class, 10)->create();
    }
}
The run() method in the above code snippet will create 10 new users using the User factory.
Advertisement