Create Dummy User Using Command in Laravel Example

Share Me
  •  
  •  
  •  
  • 2
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    2
    Shares
Create Dummy User Using Command in Laravel

Hello Dev’s Today in this example, I will give you a short example of how to create number of dummy user in laravel 8 application. Here we can create a number of user by using command as per our requirement. We need to Create Dummy User Using Command in Laravel 8 application.

So here we will generate dummy number of records which we can use in our application for our testing purpose.

Just follow below step to create few dummy user data with command:

Install Laravel 8

Here we will create laravel 8 fresh application.

composer create-project --prefer-dist laravel/laravel CreateDummyUser

Create Command

Now in this step we will create command. So, first open your terminal and then run bellow command.

php artisan make:command createDummyUser

app/Console/Commands/createDummyUser.php

Now need to update our command file like as below :

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\User;

class createDummyUser extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'create:user {user}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $totalCreateUser = $this->argument('user');

        for ($i = 0; $i < $totalCreateUser; $i++) { 
            factory(User::class)->create();
        }
    }
}

Run Command

Now run need to our command and at last of the command need pass number of user that we want to create.

As like below command will create 10 dummy user.

php artisan create:user 10

Read Also : Laravel 8 Login with Google Account Example

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →