Artisan Call output in Controller?

$command = 'foo:bar';

$params = [
        'datum' => $request->get('date'),
];

Artisan::call($command, $params);
dd(Artisan::output());

code to output inspire phrases instead of exit code

Route::get('/wisdom', function (Request $request) {
   Artisan::call('inspire');
   return Artisan::output();
});

Some off commands can not run with php artisan in controller you need to run them with shell

public function getCommand($command)
    {
        echo '<br> php artisan ' . $command . ' is running...';
        $output = new BufferedOutput;
        if(strpos($command, 'api') === false && strpos($command, 'passport') === false){
            Artisan::call($command, [], $output);
        }else{
            shell_exec('php ../artisan ' . $command);
            dump('php ../artisan ' . $command);
        }
        dump($output->fetch());
        echo 'php artisan ' . $command . ' completed.';
        echo '<br><br><a href="/admin/setting/advance">Go back</a>';
    }

This is the list of commands and api:gen and passport install just will run with shell from /bootstrap folder !

$commands = [
            [
                'id' => 1,
                'description' => 'recompile classes',
                'command' => 'clear-compiled',
            ],
            [
                'id' => 2,
                'description' => 'recompile packages',
                'command' => 'package:discover',
            ],
            [
                'id' => 3,
                'description' => 'run backup',
                'command' => 'backup:run',
            ],
            [
                'id' => 4,
                'description' => 'create password for passport',
                'command' => 'passport:client --password',
            ],
            [
                'id' => 5,
                'description' => 'install passport',
                'command' => 'passport:install',
            ],
            [
                'id' => 6,
                'description' => 'create a document for api',
                'command' => 'apidoc:generate',
            ],
            [
                'id' => 7,
                'description' => 'show list of routes',
                'command' => 'route:list',
            ],
            [
                'id' => 8,
                'description' => 'recompile config cache',
                'command' => 'config:cache',
            ],
            [
                'id' => 9,
                'description' => 'clear config cache',
                'command' => 'config:clear',
            ],
            [
                'id' => 10,
                'description' => 'run lastest migrations',
                'command' => 'migrate',
            ],
            [
                'id' => 11,
                'description' => 'run seeders',
                'command' => 'db:seed',
            ],
            [
                'id' => 12,
                'description' => 'recompile route cache',
                'command' => 'route:cache',
            ],
            [
                'id' => 13,
                'description' => 'clear route cache',
                'command' => 'route:clear',
            ],
            [
                'id' => 14,
                'description' => 'recompile view cache',
                'command' => 'view:cache',
            ],
            [
                'id' => 15,
                'description' => 'clear view cache',
                'command' => 'view:clear',
            ],
            [
                'id' => 16,
                'description' => 'optimize all configurations',
                'command' => 'optimize',
            ],
        ];