Get response from Artisan call

后端 未结 7 1422
情深已故
情深已故 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:24

    Maybe this will save some time to someone in the future, for me worked a mix of 2 answers:

    use Symfony\Component\Console\Output\StreamOutput;
    
    $stream = fopen("php://output", "w");
    Artisan::call('migrate', [
        '--path' => 'database/migrations/customer',
        '--force' => true,
        '--database' => $connectionName
    ], new StreamOutput($stream));
    
    $callResponse = ob_get_clean();
    

    StreamOutput helps to put the response in buffer and ob functions to get the response.

提交回复
热议问题