In Laravel 3 we could call Request::route()
to get the main route handling the request.
Is there any equivalent in Laravel 4?
Example of L3 code:
// in route.php
Route::any('TestRoute/(:any)', array('as' => 'NamedRoute', function() {
return print_r(Request::route());
}));
When we visit
http://servername/TestRoute/123
we get
Laravel\Routing\Route Object (
[uri] => TestRoute/(:any)
[method] => GET
[bundle] => application
[controller] =>
[controller_action] =>
[action] => Array (
[as] => NamedRoute
[0] => Closure Object ( )
[https] =>
)
[parameters] => Array ( [0] => 123 )
)
I am only interested to get the name of a Named Route from the above Object:
$namedRoute = $Route->action['as'];
It just checks if the given route name is a registered route. For example... Copy Code. Route::get('login', function() { // ... })- >name('login');
Auth::routes() is just a helper class that helps you generate all the routes required for user authentication. You can browse the code here https://github.com/laravel/framework/blob/5.8/src/Illuminate/Routing/Router.php instead.
Generally speaking, HTTP GET requests are used for reading things, while HTTP POST requests are used for creating/uploading things. I recommend reading up on HTTP verbs and what they are meant for (GET and POST are not the only ones...)
Laravel's Illuminate\Http\Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, cookies, and files that were submitted with the request.
I think you might be interested in Route::currentRouteName();
. This get's the name of the route that is currently running.
http://laravel.com/docs/routing#named-routes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With