问题
I've got an interesting problem I'd like to try and solve. Laravel has a built in "Maintenance Mode", which can be activated by calling php artisan down
in the root folder of the application. There's a setting in app/start/global.php where you can assign the view or response it makes. In my application, I have it doing this:
App::down(function()
{
// ETA Format: YYYY-MM-DD HH-MM-SS. Leave as "" to pass indeterminate time.
return View::make("maintenance", array("code" => 503,
"message" => "Service Unavailable",
"eta" => "2014-11-07 13:30:00"));
});
What this does is show a nice, clean "We'll be right back" screen, with the status message and estimated time to completion shown. Notice that I've hardcoded some parameters that get passed to the view:
code -> The http status code I want displayed
message -> A message about the nature of the disruption
eta -> A timestamp of the estimated completion time
What I'm wondering is, is there a way I can modify php artisan down
where I can pass it some parameters? For example, I want to try something like this:
php artisan down --eta="2014-11-07 13:30:00" --code="503"
So I don't have to manually code these parameters everytime I put the app into maintenance mode. I've read the docs on Laravel regarding creating artisan commands, but there's no documentation on modifying existing commands, or duplicating them and adding functionality.
If anyone has any insight into this, please let me know.
回答1:
Try creating a new command that you would call (app:down for example) that writes those options to a file, then calls the laravel down command internally e.g.
public function fire() {
$data = json_encode($this->option());
file_put_contents('/tmp/down.txt', $data);
$this->call('down');
}
Then you can pick those up in the view code...
$data = json_decode(file_get_contents('/tmp/down.txt'), true);
return View::make('maintenance', $data);
来源:https://stackoverflow.com/questions/26805599/laravel-pass-arguments-to-php-artisan-down