Get response from Artisan call

后端 未结 7 1403
情深已故
情深已故 2021-02-18 22:56

When I run in terminal php artisan migrate this results in \'Nothing to migrate\' when indeed there is nothing to migrate.

When I use Artisan::call(\'

7条回答
  •  长发绾君心
    2021-02-18 23:12

    When the Artisan command output you want is issuing an echo.

    You can access this type of output with ob_start and ob_get_clean.

    For example, if your command echos JSON.

    Artisan::command('myecho:command', function () {
    
        echo json_encode(config('myconfig'), true);
    
    })->describe('outputs json');
    

    Then you can access the JSON output by wrapping the command call in a buffer:

    \ob_start();
    \Artisan::call('myecho:command');
    $output = \ob_get_clean();
    
    var_dump($output);
    

提交回复
热议问题