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());