Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lambdaloopers's avatar

Custom Authentication with Laravel 6 and passport

I'm trying to make authentication via api in laravel, use custom fields to login and also use custom fields instead of the default Email, I'm not able to do that and I'm quite lost. Don't know if it is even possible.

So far I tried this:

otherusers entity
- idnumber
- password

auth.php

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'otherusers',
            'hash' => false,
        ],
],
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Domain\Entities\User::class,
        ],
        'otherusers' => [
            'driver' => 'eloquent',
            'model' => App\Domain\Entities\OtherUser::class,
        ],
    ],

And then In the authcontroller I try to use this.

$credentials = [ 'idnumber' => $theidnumber , 'password' => $thepassword ]
Auth::guard('api')->check($credentials);
//Also tried with attempt but it says unknown method.

Obiously I adapted the naming, any hint?

0 likes
1 reply

Please or to participate in this conversation.