Laravel 6 Create Dummy User Using Command Example

10-Apr-2023

.

Admin

Laravel 6 Create Dummy User Using Command Example

hii guys,

In this example,I will show you how to create number of dummy user in laravel 6 application. you can create number of user using command as per your requirement.

Here will generate dummy number of records which you can use in your application for testing purpose.

Follow below step to create dummy user data with command:

Install Laravel 6


you will create laravel 6 fresh application.

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

Create Command

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

php artisan make:command createDummyUser

app/Console/Commands/createDummyUser.php

update your 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 your command and at last of the command pass number of user that you want to create.

below command will create 10 dummy user.

php artisan create:user 10

It will help you....

#Laravel

#Laravel 6