Код: Выделить всё
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
];
Код: Выделить всё
public function handle($request, Closure $next)
{
if ($this->auth->check()) {
$user = $this->auth->user();
$currentDateTime = strtotime('Y-m-d H:i:s');
$tokenExpirationTile = strtotime($user->token_expiration);
if ($currentDateTime auth->logout();
redirect('home/login')->with('message', 'Your session has expired. Please login in again');
}
} else {
redirect('home/login')->with('message', 'Please login before attempting to access that');
}
}
Код: Выделить всё
Route::get('home/dashboard', 'HomeController@dashboard', ['middleware' => 'auth']);
Когда я пройду dd() в функции handle ничего не происходит.
Как мне заставить его запустить этот метод на этом маршруте?
Кроме того, когда речь идет о других контроллерах, где вам необходимо пройти аутентификацию перед каждым запросом действия, как сказать: «перед каждым действием запускайте этот метод». В рельсах я бы сделал before_action :method_name
Подробнее здесь: https://stackoverflow.com/questions/326 ... in-laravel
Мобильная версия