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

Sanmie's avatar

Auth::Login($user) returns Undefined array key "driver" on custom User model

Hey, my last use of Laravel and php was quite a while ago and I'm currently working on a project which uses Patreon as the Authentication method.

But after calling Auth::login($user) I get

Undefined array key "driver"

My current code looks like this:

Model


namespace App\Models;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable 
{
    use HasApiTokens, HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'patreonId',
        'tierId',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'remember_token',
    ];
}

config/auth.php

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

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

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],
    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

And my login controller where I want to login the user inside the patreon Callback

public function handleProviderCallback(PatreonCredentials $credentials)
    {
      //Some code to get everything needed to create or update existing users inside my users table here

	    $user = User::where('patreonId', $patreonUser->id)->first();
        if (!$user) {
            $user = User::create([
                'name' => $patreonUser->name,
                'email' => $patreonUser->email,
                'tierId' => $tierId,
                'patreonId' => $patreonUser->id
            ]);
        }else{
            if($tierId != $user->tierId){
                $user->tierId = $tierId;
                $user->save();
            }
        }
        Auth::login($user,true);
        $token = $user->createToken('Patreon Token')->accessToken;
        return redirect()->to('/')->with('token', $token);
    }

Edit: Forgott to add I'm on Laravel version 10.2.0 Edit2: Forgot to add the guard defaults

0 likes
1 reply
Sanmie's avatar
Sanmie
OP
Best Answer
Level 1

Nevermind my code was working just fine. I just forgott to

php artisan config:cache

after adding the default guard

sorry for wasting your time :O

Please or to participate in this conversation.