You can use the "call" method provided by this facade and then specify the command as the first argument and any parameter for the command on the second parameter.
use Illuminate\Support\Facades\Artisan; Artisan::call('migrate'); // equivalent of calling "php artisan migrate" Artisan::call('make:model User'); // equivalent of calling "php artisan make:model User"
You can programmatically call the artisan console command from anywhere within your application just that ensure the application runs through the code to get the command executed.
Console Command With Parameters
To pass in the parameter for the command, you can add it as key and value pair for the second parameter of the "call" method like below.
Artisan::call('mail:send', [ 'user' => User::first(), '--queue' => 'default' ]);
Leave a reply