How to know the current route in Laravel 4?

0

In Laravel 5, we can get the current route (say the class instance) using the Illuminate\Http\Request class, using the route method.

So:

 public function handle(Request $request)
 {
       $rota = $request->route();
 }

What about Laravel 4? How can I do this?

I need to know at a certain point what the current route is being requested.

For example:

  App::before(function ($request)
  {
      $rota = /** Quero descobrir como pegar a rota atual aqui **/
  });
    
asked by anonymous 12.04.2016 / 18:15

2 answers

2

Very well, Lord @WallaceMaxters! This is very simple.

Just use the Route::getCurrentRoute() method.

It is first of all important to remember that this will only work on filters and App::after . No App::before will not work, because by logic, the route has not yet been processed, so that the instance is returned by Laravel .

Here's an example:

 Route::filter('auth', function ()
 {
       dd(Route::getCurrentRoute()->getName());
 });
    
15.04.2016 / 00:58
1
Route::getCurrentRoute()->getName()

The cool thing is that it also works on the other versions (larger than the 4 ) of Laravel     

03.08.2018 / 16:22