did you remove
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
//
}
Does your User model implement interface Illuminate\Auth\UserInterface?
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 {
Do the tests automatically have access to Laravel's facades or do I need to add something?
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
Realised that my Seeder class wasn't structured properly so it was only seeding the memory database for the very first test.
Sorted now.
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community