Is there a way, in Laravel 5, to call routes internally/programmatically from within the application? I've found a lot of tutorials for Laravel 4, but I cannot find the information for version 5.
相关问题
- Laravel Option Select - Default Issue
- Laravel 5.1 MethodNotAllowedHttpException on store
- Laravel - Implicit route model binding with soft d
- laravel : php artisan suddenly stop working
- How to execute MYSQL query in laravel?
相关文章
- laravel create model from custom stub when using p
- send redirect and setting cookie, using laravel 5
- How to send parameters to queues?
- Bcrypt vs Hash in laravel
- Laravel: What's the advantage of using the ass
- How to make public folder as root in Laravel?
- Input file in laravel 5.2?
- What is the difference between Session::set and Se
None of these answers worked for me: they would either not accept query parameters, or could not use the existing app() instance (needed for config & .env vars).
I want to call routes internally because I'm writing console commands to interface with my app's API.
Here's what I did that works well for me:
Your Controller/Route will work exactly as if you had called it using
curl
. Have fun!You can actually call the controller that associates to that route instead of 'calling' the route internally.
For example:
Routes.php
UserController.php
Instead of calling
/getUser
route, you can actually callUserController@getUser
instead.This is the same as
calling
the route internally if that what you mean. Hope that helpsUsing laravel 5.5, this method worked for me:
Source: https://laracasts.com/discuss/channels/laravel/route-dispatch
*note: maybe you will have issue if the route you're trying to access has authentication middleware and you're not providing the right credentials. to avoid this, be sure to set the correct headers required so that the request is processed normally (eg
Authorisation bearer ...
).You may try something like this: