Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of Request::route() in Laravel 4?

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'];
like image 291
igaster Avatar asked Jun 04 '13 08:06

igaster


People also ask

What is Route :: has in Laravel?

It just checks if the given route name is a registered route. For example... Copy Code. Route::get('login', function() { // ... })- >name('login');

What does Auth :: Routes () do?

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.

What is the difference between Route :: get and Route :: post?

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...)

What is request method in Laravel?

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.


1 Answers

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

like image 189
Bitbored Avatar answered Sep 29 '22 12:09

Bitbored