Reputation: 373
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
Upvotes: 1
Views: 490
Reputation: 116
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
Upvotes: 2