Get response from Artisan call

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

    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.

提交回复
热议问题