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?
To execute php artisan serve stop simply goto your commnad line where your server is running and press ctrl+c. It will stop your server.
Simply use Ctrl + C . It will come out to prompt state.
Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.
$command = 'foo:bar';
$params = [
'datum' => $request->get('date'),
];
Artisan::call($command, $params);
dd(Artisan::output());
code to output inspire phrases instead of exit code
Route::get('/wisdom', function (Request $request) {
Artisan::call('inspire');
return Artisan::output();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With