I am using Laravel 4.2 framework (will be upgraded soon) and am calling an artisan
command from a controller with a return redirect back.
My issue is when I call the command, the command echo
some stuff for me (which is helpful when I call it from the terminal) but now since am using it in a method, I want the same echos
showing in my view as flash message.
I will write the following example just to clarify my issue.
My Command:
public function fire()
{
// Do stuff.
echo $vars
}
My Controller:
function foo() {
// Some input here
Artisan::call('command');
return Redirect::back(); // <-- want to add the echos of the command.
}
So I want to show the $var
in my views, am not sure if it's possible if not am open to other suggestions that can give me the same concept (keep in mind if am replacing the echo
with something else it got to show in both view and terminal when I run the command).
Note: I tried Ajax but my issue was with me sending a file as param, tried the FormData Object but it didn't work with me.
I fixed the problem by changing my command little bit.
Command:
function fire()
{
// replaced the echo with the following.
$this->info('what ever you want ur message you want to put in console');
}
Controller
function foo()
{
$output = new BufferedOutput();
Artisan::call('command', [arguments], $output);
return Redirect::back()->with('flash_message', $output->fetch());
}
Guess the buffered output works with command outputs which can be found in Laravel Documentations not echo's