本文介紹了如何使用帶有自定義用戶名列的 Laravel Passport的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
現在我正在使用類似的東西來驗證我的基本站點上的用戶:
Now I'm using something like that for authenticating the user on my base site:
if (Auth::attempt($request->only(['id', 'password']))) {
//
}
如何修改此代碼以使用自定義列作為用戶名?https://laravel.com/docs/5.3/passport#password-grant-tokens
How can I modify this code for using custom column as username? https://laravel.com/docs/5.3/passport#password-grant-tokens
推薦答案
您可以在用戶模型中使用 findForPassport 方法.
You can use findForPassport method in your user model.
該方法以用戶名為參數,返回用戶模型
This method take username as argument, and return user model
例如:
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
// ... some code
public function findForPassport($username) {
return $this->where('id', $username)->first();
}
}
這篇關于如何使用帶有自定義用戶名列的 Laravel Passport的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!