Search code examples
laravellaravel-passport

Laravel Passport 'App\\User' not found?


My 'User' model is inside 'App\Models\User.php', and when I do this:

    use GuzzleHttp\Client;

    $client = new Client();
    $response = $client->request('POST', 'http://localhost/oauth/token', [
        'form_params' => [
        'username'      => $data['username'],
        'password'      => $data['password'],
        'client_id'     => env('PASSWORD_CLIENT_ID'),
        'client_secret' => env('PASSWORD_CLIENT_SECRET'),
        'grant_type'    => 'password'
      ]
    ]);

Iam getting this error:

"message": "Server error: `POST http://localhost/oauth/token` resulted in a `500 Internal Server Error` response:\nClass 'App\\User' not found\n",

It seems Passport is looking for 'User' model inside 'App' directory, not the 'Model' directory which is the right place.

How to solve this ?


Solution

  • In your config/auth.php file search for the providers key and change the model from App\User::class to App\Model\User::class:

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Model\User::class, // <-- this line
        ],
    
        //
    ],
    

    Then delete the configuration cache via php artisan config:clear.