When i login into a admin form when the username and password are correct it will direct me into my user login form not on my desire location which is admin/home
ADMIN/AUTH/LOGINCONTROLLER
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/admin/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest.admin', ['except' => 'logout']);
}
public function showLoginForm()
{
return view('admin.auth.login');
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard('admins');
}
1 回答
我会创建一个中间件来检查用户是否为Admin并将无管理员重定向到home然后将该中间件添加到kernel.php中的管理路由
然后您的标准登录控制器将适用于这两种情况
你的中间件看起来像这样 .
使用php artisan make:中间件名称 - 这里
然后使用标准登录控制器重定向到主页 . 如果请求admin / home,您将被重定向到登录,当用户登录并且是Admin时,他将被重定向到admin / home .
在您的管理控制器中,您可以使用
添加到kernel.php中间件
注意isAdmin是我的用户模型中的一个函数,用于确定用户是否为Admin