Created
December 7, 2015 09:31
-
-
Save dave1010/3081f4491d1216543692 to your computer and use it in GitHub Desktop.
Call a route in Laravel. Doens't quite work properly IIRC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Illuminate\Routing\Router; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class CallRoute extends Command { | |
protected $name = 'route:call'; | |
protected $description = 'Call route from CLI'; | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function fire() | |
{ | |
parse_str($this->option('query'), $params); // by ref | |
$request = Request::create( | |
$this->option('uri'), | |
$this->option('method'), | |
$params | |
); | |
$this->info(app()[Router::class]->handle($request)); | |
} | |
protected function getOptions() | |
{ | |
return [ | |
['uri', null, InputOption::VALUE_REQUIRED, 'The path of the route to be called', null], | |
['method', null, InputOption::VALUE_OPTIONAL, 'HTTP method (eg GET, POST)', 'GET'], | |
['query', null, InputOption::VALUE_OPTIONAL, 'Urlencoded GET params. Uses parse_str()', null], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment