laravel 5.5 auth middleware, redirect to login page, can show some message?
when use auth middleware, it redirect to login page if user did not login, how can i show some message like "you have to login to access this page" when redirect to login page?
In the exception handler which is found in App\Exceptions\Handler you can add a flash message when AuthenticationException is thrown.
public function render(Exception $exception)
{
if ($exception instanceof AuthenticationException) {
Session::flash('login-error', 'You must be logged in to do that...');
}
return parent::render($exception);
}
Then in your login view, check for that error in the session and display a message when it is present.