In my application, I am username as email or phone number. so username can be email or phone number. But laravel passport accepts username as email. And I want to generate password grant type token with email and password or phone_no and password. so required values to generate token will be
Use findForPassport method in user model. Like below
class User extends Authenticatable {
use HasApiTokens;
public function findForPassport($username) {
return self::firstWhere('email', $username) ?? self::firstWhere('phone_no', $username);
}
}
Also you can read this document https://laravel.com/docs/8.x/passport#customizing-the-username-field
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.