How to create and run user seeder in laravel

Updated at 22-Jul-2021, By samar

How to create and run user seeder in laravel

Hello everyone, in this post we will examine how to solve the "How to create and run user seeder in laravel" programming puzzle.

Seeding is used to insert dummy data for your project. You can create a seeder class and run that class to seed data using artisan command in laravel
  • Create user seeder and seed data for users table

    php artisan make:seeder UserSeeder
    
    //database\seeders\UserSeeder.php
    <?php
    
    namespace Database\Seeders;
    
    use Illuminate\Database\Seeder;
    use App\Models\User;
    class UserSeeder extends Seeder
    {
        /**
         * Run the database seeds.
         *
         * @return void
         */
        public function run()
        {
            //
            $users = User::factory()->count(5)->create();
        }
    }
    
    php artisan db:seed --class=UserSeeder
    

Back to code snippet queries related laravel