Reputation: 7128
I have custom command like:
php artisan down --message="this is my custom message."
Now I want to use this command in my controller with input fields.
I know I can use Call
method like Artisan::call('down');
but my issue is how to add --message=""
part into that call method?
this is what I'm sending to controller currently:
array:3 [▼
"_token" => "wqHyTNmDhArtonB0gwhIbCipSsStv0WnoASQm34u"
"maintenance_message" => "this is my custom message."
"maintenance" => "active"
]
Now based on maintenance
value i will call Artisan::call('up');
or Artisan::call('down');
but the question is how do i add maintenance_message
into it?
This is my current function.
public function MaintenanceMode(Request $request){
if($request->input('maintenance') == 'active'){
//maintenance_message
Session::flash('danger', 'Site is successfully in maintenance mode.');
return Artisan::call('down');
}else{
//maintenance_message
Session::flash('success', 'Site is ONLINE.');
return Artisan::call('up');
}
}
Any idea?
Upvotes: 0
Views: 996
Reputation: 7128
Here is what I did to add my message part into artisan command
return Artisan::call('down', ['--message' => $request->input('maintenance_message')]);
Hope it help others.
Upvotes: 1
Reputation: 180024
The documentation has some examples of this:
https://laravel.com/docs/5.7/artisan#programmatically-executing-commands
The call method accepts either the command's name or class as the first argument, and an array of command parameters as the second argument. The exit code will be returned:
Route::get('/foo', function () { $exitCode = Artisan::call('email:send', [ 'user' => 1, '--queue' => 'default' ]); // });
Upvotes: 2