Skip to content

Instantly share code, notes, and snippets.

@dave1010
Created December 7, 2015 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave1010/3081f4491d1216543692 to your computer and use it in GitHub Desktop.
Save dave1010/3081f4491d1216543692 to your computer and use it in GitHub Desktop.
Call a route in Laravel. Doens't quite work properly IIRC
<?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