2016-02-24 248 views
0

我是Laravel的初學者。Laravel身份驗證混淆

我想用:

Auth::login(users::find(1)) 

結果: 類型錯誤:傳遞給照亮\身份驗證\ SessionGuard ::登錄(參數1)必須是照亮\合同的實例\驗證\可驗證,應用程序\用戶實例

我更改了模型以擴展Authenticatable而不是Model。 我也改變了驗證聲明:

Auth::login(users::where('id', 1)) 

結果: 類型錯誤:傳遞給照亮\身份驗證\ SessionGuard ::登錄()必須實現接口照亮\合同參數1 \身份驗證\鑑別的,例如照亮\數據庫\雄辯\ Builder中給出

我不知道你會幫我,「欣賞」

回答

2

你,應該實現照亮\ \合同驗證\可驗證的用戶模型類通過驗證::登錄

Authenticate A User Instance

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:

Auth::login($user);

https://laravel.com/docs/5.1/authentication

或者你可以簡單地這樣做:

Auth::loginUsingId(1);