简体   繁体   中英

Execute laravel route from a Artisan console command

how to execute a route request and get response from artisan console command class?

I have tried method suggested by others, which does not work as expected.

$request = Request::create('/', 'GET');
.
.
.
$response =  $route->run($request);

[using laravel 5]

Try this

$router = new Illuminate\Routing\Router(new Illuminate\Events\Dispatcher);

$request = Illuminate\Http\Request::create('', 'GET');

$router->dispatch($request);

From your code above I think you're confusing a route and the router. A route just contains information about how a single URI should be handled. The router itself compiles all your routes and determines the correct route to dispatch the request to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM