多身份验证使用一页登录laravel

多身份验证使用一页登录laravel,laravel,laravel-5,laravel-5.5,Laravel,Laravel 5,Laravel 5.5,我是拉威尔的新手,但我对多作者拉威尔很好奇。我想做一些网站,其中有两个规则,客户和卖家。但是,我希望他们使用相同的登录表单登录。我尝试使用php artisan make:auth,但我不明白如何在一个控制器中使用它使用LoginController.php,从我在许多教程中看到的情况来看,它与不同的登录表单和控制器分开。如客户登录表单和卖家登录表单。是否可以仅使用一个登录表单和一个登录控制器进行多重身份验证 谢谢我认为您可以在LoginController中覆盖attemptLogin()方法

我是拉威尔的新手,但我对多作者拉威尔很好奇。我想做一些网站,其中有两个规则,客户和卖家。但是,我希望他们使用相同的登录表单登录。我尝试使用php artisan make:auth,但我不明白如何在一个控制器中使用它使用LoginController.php,从我在许多教程中看到的情况来看,它与不同的登录表单和控制器分开。如客户登录表单和卖家登录表单。是否可以仅使用一个登录表单和一个登录控制器进行多重身份验证


谢谢

我认为您可以在
LoginController
中覆盖
attemptLogin()
方法,如下所示:

protected function attemptLogin(Request $request)
{
    $customerAttempt = Auth::guard('customer')->attempt(
        $this->credentials($request), $request->has('remember')
    );
    if(!$customerAttempt){
        return Auth::guard('seller')->attempt(
            $this->credentials($request), $request->has('remember')
        );
    }
    return $customerAttempt;
}
public function login(Request $request)
{
    // Validate the form data
    $validator = $this->validate($request, [
    'email'   => 'required|email',
    'password' => 'required|string'
  ]);

    // Attempt to log the customer in
    if (Auth::guard('customer')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
        // if successful, then redirect to their intended location
        return redirect()->intended(route('Put_your_URL'));
    } //attempt to log the seller in
    else if (Auth::guard('seller')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
        // if successful, then redirect to their intended location
        return redirect()->intended(route('Put_your_URL'));
    }

    // if Auth::attempt fails (wrong credentials) create a new message bag instance.
    $errors = new MessageBag(['password' => ['Adresse email et/ou mot de passe incorrect.']]);
    // redirect back to the login page, using ->withErrors($errors) you send the error created above
    return redirect()->back()->withErrors($errors)->withInput($request->only('email', 'password'));
}