Skip to content
Advertisement

BadMethodCallException: Call to undefined method AppModelsUser::getFirstMedia()

I am trying to do:

$this->assertFileExists($user->getFirstMedia()->getPath()); In my test. But when I run it I get this error:

BadMethodCallException: Call to undefined method AppModelsUser::getFirstMedia().

I do:

JavaScript

And I also do:

JavaScript

As far as I know I am using the right traits. What am I doing wrong here?

EDIT:

My test:

JavaScript

My store method controller code:

JavaScript

Advertisement

Answer

You are implementing your traits in a TestCase, that is not correct. If you are accessing your users media, you should implement the traits on the User.php model class, its either located in app/User.php or app/Models/User.php.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement