Get response from Artisan call

For me with Laravel 5.1 all this did not work but you can simply use:

Artisan::output()

The return result of all commands is defined in the class Symfony\Component\Console\Command\Command, method run:

return is_numeric($statusCode) ? (int) $statusCode : 0;

The $statusCode variable is set by calling the command's execute method, which in artisan's case is defined in the class Illuminate\Console\Command:

protected function execute(InputInterface $input, OutputInterface $output)
{
    return $this->fire();
}

The result of the fire method is left up to the individual commands, in the case of php artisan migrate command, nothing is returned from the method so the $statusCode is null (which is why you get the 0 returned from Symfony\Component\Console\Command\Command::run method)

If you want to get a response back from a custom command, just return an integer back from your fire method and it will bubble back up into the $statusCode. You can use that to programmatically switch against different results of your custom command.

If you specifically want to get the result from the artisan:migrate command, then I don't think there's much you can do to change the return value besides wrapping the command in your own custom command that calls it.


I'm able to get the output of Artisan::call() with the via the following:

use Symfony\Component\Console\Output\StreamOutput;

$stream = fopen("php://output", "w");
Artisan::call("migrate", array(), new StreamOutput($stream));

var_dump($stream);