Support the ongoing development of Laravel.io →
Authentication
Last updated 1 year ago.
0

did you remove

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {
    //
}
Last updated 1 year ago.
0

Does your User model implement interface Illuminate\Auth\UserInterface?

Last updated 1 year ago.
0

Nope, User model hasn't been changed from inital Laravel setup:

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {
Last updated 1 year ago.
0

Do the tests automatically have access to Laravel's facades or do I need to add something?

Last updated 1 year ago.
0

Or does the fact that this test is in a subfolder of the app/tests directory cause any issue? Here's my tests directory structure:

app > tests > api > v1 > AccountsApiControllerTest.php

Last updated 1 year ago.
0

Realised that my Seeder class wasn't structured properly so it was only seeding the memory database for the very first test.

Sorted now.

Last updated 1 year ago.
0

For others who hit the same error and stumble into this thread looking for help, another thing to double-check is that a user identified by $id actually exists in the database.

In my case I had written a custom Auth provider that wasn't throwing an error if retrieveById() couldn't find the requested user. It was just returning what first() returns if there are no records found, which is null. Unfortunately the loginUsingId() method doesn't validate if the retrieveById() method returned a valid user - it just throws the result straight into the login() method within the Guard class. And because null doesn't implement the UserInterface you end up with that exception. So whilst the exception returned is technically correct, it doesn't make it immediately obvious what the root cause of the problem is.

Last updated 1 year ago.
0

jamesggordon said:

For others who hit the same error and stumble into this thread looking for help, another thing to double-check is that a user identified by $id actually exists in the database.

In my case I had written a custom Auth provider that wasn't throwing an error if retrieveById() couldn't find the requested user. It was just returning what first() returns if there are no records found, which is null. Unfortunately the loginUsingId() method doesn't validate if the retrieveById() method returned a valid user - it just throws the result straight into the login() method within the Guard class. And because null doesn't implement the UserInterface you end up with that exception. So whilst the exception returned is technically correct, it doesn't make it immediately obvious what the root cause of the problem is.

That solves my problem. You're right, Id doesn't exists in my database. Thanks for you help.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.