App\Http\Controllers\Auth\LoginController.php after logging user
App\Http\Middleware\RedirectIfAuthenticated.php if logged
Use route if you have different login route
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I created a new Middleware called "MustBeAdmin", and in my function depending of the account_type_id i give permission or not, but i notice for example when i access a page without being authenticate im redirect to "/login" route, but since my default redirect cant be this route, i need to change it, but i cant find where i change this default route. Im using Laravel 5.4.
My Middleware is:
public function handle($request, Closure $next)
{
if(auth()->check() && auth()->user()->account_type_id == 1){
return $next($request);
}
return redirect('/admin');
}
@mbpp the path is defined in app/Exceptions/Handler.php
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest('elsewhere');
}
change the 'elsewhere' to the url of the login page or where you want unauthenticated users to be redirected to.
Please or to participate in this conversation.