Laravel自定义守护记住我功能不与AuthenticateUser特性一起使用

时间:2018-10-12 13:35:18

标签: laravel

我创建了一个使用AuthenticatesUsers特性的第二个后卫姓名客户,除了每次登录后似乎都无法注销的“记住我”功能外,其他一切似乎都运行良好。所以我想请记住我正在使用默认防护,那么如何解决此问题?我可以在登录控制器中解决该问题吗?

客户登录控制器

<?php

namespace App\Http\Controllers\CustomerAuth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;
use App\Customer;
class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    protected function guard()
    {
    return Auth()->guard('customer');
    }

    public function showLoginForm()
    {
        if(Auth::user() || Auth::guard('customer')->user())
        {
            return redirect('/');
        }
        else{
            return view('customer-auth.login');
        }
    }





}

AuthenticateUser.php

    protected function attemptLogin(Request $request)
{
    return $this->guard()->attempt(
        $this->credentials($request), $request->filled('remember')
    );
}

1 个答案:

答案 0 :(得分:0)

我使用了一些自定义守卫。我必须制作一个使用

的新注销方法
\Auth::guard($guard)->logout(); 

因为默认情况下,StatefulGuard.php中的logout()方法不接受任何参数,例如警卫。