A
A
Abc Edc2015-09-07 09:45:13
Laravel
Abc Edc, 2015-09-07 09:45:13

How to take route name in laravel in middleware?

routes.php

Route::group(['middleware' => 'access'], function () {
      Route::resource('some', 'SomeController');
});

Attempt to take route name
namespace App\Http\Middleware;

use Closure;

class AccessMidleware
{
    
    public function handle($request, Closure $next)
    {
        dd(\Route::currentRouteName()); //К сожалению тут null
        //return $next($request);
    }
}

kernel.php
protected $routeMiddleware = [
    ...
    'access'=>'App\Http\Middleware\AccessMidleware'
  ];

Why is it always null in the dump, how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy Samoilenko, 2015-09-07
@gleber1

So you don't have a route name set.
Try asking it like this:

Route::group(['middleware' => 'access', "as" => "RouteName"], function () {
      Route::resource('some', 'SomeController');
});

And everything will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question