Laravel 5.1 MultiAuth登录

时间:2015-10-09 14:34:56

标签: php laravel laravel-5.1

我使用了https://github.com/Kbwebs/MultiAuth并完成了所有步骤 我进行注册,但在我输入时登录,如果是管理员,则输入第一个数组,管理员只登录,客户不要使用Auth.php

'multi-auth' => [
    'admin' => [
        'driver' => 'eloquent',
        'model'  => App\AdminModel::class
    ],
    'customer' => [
        'driver' => 'eloquent',
        'model'  => App\CustomerModel::class
    ]
],

postLogin()

   public function postLogin(Request $request)
    {
        $this->validate($request, [
            $this->loginUsername() => 'required', 'password' => 'required',
        ]);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.

        $throttles = $this->isUsingThrottlesLoginsTrait();

        if ($throttles && $this->hasTooManyLoginAttempts($request)) {
            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->getCredentials($request);


        if (Auth::admin()->attempt($credentials, $request->has('remember'))) {
           return redirect('Admin');
        }

        if (Auth::customer()->attempt($credentials, $request->has('remember'))) {
           return redirect('/');
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.

        if ($throttles) {
            $this->incrementLoginAttempts($request);
        }

        return redirect($this->loginPath())
            ->withInput($request->only($this->loginUsername(), 'remember'))
            ->withErrors([
                $this->loginUsername() => $this->getFailedLoginMessage(),
            ]);
    }

0 个答案:

没有答案