I have a complex Artisan Command that I wanna call in my Controller also. That works. Except that it return an Exitcode instead of output.

use Symfony\Component\Console\Output\BufferedOutput; # on top

public function foobar(Request $request)
{
    $this->validate($request, [
        'date' => 'required|date_format:Y-m-d',
    ]);

    $output = new BufferedOutput;

    $exitCode = Artisan::call('foo:bar', [
        'datum' => $request->get('date'),
    ], $output);
    return $exitCode; # returns 0;
    return dd($output->fetch()); # returns ""
}

I want the output of the command. How to do that? The last line of my Artisan command has a return on the last line that should be returned.. How?

推荐答案

$command = 'foo:bar';

$params = [
        'datum' => $request->get('date'),
];

Artisan::call($command, $params);
dd(Artisan::output());

Laravel相关问答推荐

如何通过 Eloquent 获取单个集合中每位教师的学生人数

Laravel Livewire 组件属性在 div 类中为空

Laravel API 版本控制文件夹 struct

如何监控 Laravel 队列是否正在运行?

在 laravel 的集合中找到?例子

刚安装 Lumen 并得到 NotFoundHttpException

具有实时和 WebSockets 的 Angular2 + Laravel

使用限制排队 Guzzle 请求

如何更改 Handlebars.js 的默认分隔符?

Laravel - 批量分配异常错误

如何使用中间件将标头添加到响应中?

在 Laravel 5 中找不到类App\Http\Controllers\Artisan

Filesystem.php 中的 ErrorException

Laravel 5 Mime 验证

Laravel Mix 生成字体到另一个目录

控制器中的laravel foreach循环

Laravel 部署……有标准的方式吗?

Laravel or where

Laravel 将附加参数传递给函数

连接到 tcp://smtp.mail.yahoo.com:465 超时