Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

A surprising issue with the Auth user and tests

And why it happens

Joel Clermont
Joel Clermont
2025-09-26

From our daily Laravel tips email. Get the next one in your inbox.

In a previous video, I talked about one aspect of Eloquent strictness checks: lazy loading.

In today's video, I want to show a surprising issue with another strictness check: missing attribute access.

When working with factory-generated data in a test, you might get an exception with this strictness check, when you really wouldn't expect one.

Let's see why it works this way, and how to prevent it from making our tests fail.

Watch Now (6 min)

And after watching, don't forget to subscribe to our YouTube channel, so you don't miss future videos.

Here to help,

Joel

P.S. Eloquent strictness is one easy way to get more confident with your code. Ash has published a helpful guide with many more tips to make your Laravel apps "battle ready".

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.