Laravel - Artisan Console - Programmatically Executing Commands

Sometimes you may wish to execute an Artisan command outside of the CLI. For example, you may wish to execute an Artisan command from a route or controller. You may use the call method on the Artisan facade to accomplish this. The call method accepts either the command's signature name or class name as its first argument, and an array of command parameters as the second argument. The exit code will be returned:

    use Illuminate\Support\Facades\Artisan;
    Route::post('/user/{user}/mail', function ($user) {
        $exitCode = Artisan::call('mail:send', [
            'user' => $user, '--queue' => 'default'

Alternatively, you may pass the entire Artisan command to the call method as a string:

    Artisan::call('mail:send 1 --queue=default');