Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.