Insert dummy data in users table Laravel

Updated at 03-Mar-2022, By samar

Insert dummy data in users table Laravel

Hello everyone, in this post we will examine how to solve the "Insert dummy data in users table Laravel" programming puzzle.

Sometimes we have to insert dummy data in the users table of the Laravel project. Here we provide one of the easiest ways to insert dummy data in the users table.
  • 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