2016-10-12 33 views
1

我想實現無需laravel應用程序密碼的登錄驗證用戶沒有密碼,但它顯示了一個錯誤:Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, string given ,我使用的代碼是:試圖在Laravel

$checkUser = '[email protected]'; 


    Auth::login($checkUser, true); 

請幫我解決這個問題。

回答

1

If you need to log an existing user instance into your application, you may call the login method with the user instance. The given object must be an implementation of the Illuminate\Contracts\Auth\Authenticatable contract. Of course, the App\User model included with Laravel already implements this interface:

$ checkUser必須是雄辯的實例。所以你需要認證用戶之前訪問雄辯

$checkUser=App\User::where('email','[email protected]')->first(); 
Auth::login($checkUser, true); 

的情況下,你知道的用戶ID只用登錄使用ID

Auth::loginUsingId(1); 
// Login and "remember" the given user... 
Auth::loginUsingId(1, true); 
3

考慮您的電子郵件列名是email,嘗試

$user = User::whereEmail('[email protected]')->first(); 
Auth::login($user) 

Auth::loginUsingId($user->id);