tehcpu tehcpu - 1 year ago 495
PHP Question

How to use Laravel Passport with a custom username column

Now I'm using something like that for authenticating the user on my base site:

if (Auth::attempt($request->only(['id', 'password']))) {

How can I modify this code for using custom column as username?

Answer Source

You can use findForPassport method in your user model.

This method take username as argument, and return user model

For example:

class User extends Authenticatable
    use HasApiTokens, Notifiable;

    // ... some code

    public function findForPassport($username) {
        return $this->where('id', $username)->first();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download