Somebody...please help me in this case..
Admin and user login redirection
In my project, i am having a user login page and admin login page. I want my admin login page to redirect to admin-login.blade.php view on successful authentication and redirect back to admin login page on unsucessful, and i also want it redirect to admin-dashboard.blade.php if admin is already authenticated not to the admin login page. I have written code in RedirectIfAuthenticated.php to make it happen as below.
switch ($guard) { case 'admin': if(Auth::guard($guard)->check()) { return redirect()->route('admin.dashboard'); }
break;
default:
if (Auth::guard($guard)->check())
{
return redirect('/home');
}
break;
}
return $next($request);
And in Handler.php as below:-
if ($request->expectsJson()) { return response()->json(['error' => 'Unauthenticated.'], 401); }
$guard=array_get($exception->guards(),0);
switch ($guard) {
case 'admin':
# code...
$login='admin.login';
break;
default:
# code...
$login='login';
break;
}
return redirect()->guest(route($login));
web.php
Route::get('/home', 'HomeController@index')->name('home'); Route::prefix('admin')->group(function() { Route::get('/login','Auth\AdminLoginController@showLoginForm')->name('admin.login'); Route::post('/login','Auth\AdminLoginController@login')->name('admin.login.submit'); Route::get('/', 'AdminController@index')->name('admin.dashboard'); });
Please or to participate in this conversation.