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

当我在代码中使用Artisan::call('migrate')时(在自定义Artisan命令中使用它),这不会返回任何消息.它只是执行代码,没有任何反馈.

如果我把Artisan::call方法的结果设为vardump(),它只会返回int(0)

Is it possible to get the response of the Artisan call method?

推荐答案

所有命令的返回结果在类Symfony\Component\Console\Command\Command、方法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)

如果想从自定义命令返回响应,只需从fire方法返回一个整数,它就会跳回$statusCode.您可以使用它以编程方式根据自定义命令的不同结果进行切换.

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.

Laravel相关问答推荐

按回车键时如何防止此功能运行?

我如何通过 laravel 在高图中针对不同的时间范围进行烛台数据分组

如何通过 Controller 访问 Laravel 中 Model 的值?

Laravel Debugbar 中的 Laravel api routes路由

如何在自引用表上使用 Laravel 的 hasManyThrough

Eloquent/Laravel:是否有 object->load('relation') 的对应物,例如.object->unload('relation')?

如何在 Laravel 的外部 js 文件中包含 csrf_token()?

laravel Eloquent 模型更新事件未触发

.gitignore 不忽略文件夹

Laravel - 排序的集合输出不是数组

在 Laravel 5 中扩展请求类

路由模型绑定不起作用

在 Laravel 4 迁移中创建 MYSQL 过程

在 AWS 上找不到 Laravel 5 类Collective\Html\HtmlServiceProvider

在 Laravel 中显示已注册的路由

Laravel 同步错误

如何在 Laravel 5.1 中改变环境?

Laravel 在特定文件夹中创建迁移文件

干预图像:直接从带有原始文件名和分机的网址保存图像?

Laravel Queue,Beanstalkd vs Database,有什么区别?