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

How much detail should you include in error messages?

Error messages are part of user experience.

Joel Clermont
Joel Clermont
2023-10-24

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

It's no secret, we love Laravel validation rules. They make it so painless to enforce data and business logic on user input.

Out of the box, the validation error messages provided by Laravel are pretty clear. But it's still worth giving them a thought, especially when we're enforcing some custom business rules.

For example, let's say we have a form request where it requires a related job posting record to not be expired. How should that be presented to a user if they try to submit against an expired record?

We could be vague and return an HTTP 403 - maybe there's no way we think they should ever be able to navigate to a spot where submitting against an expired record is possible. But what about someone who leaves a tab open longer than we expect? Or a bookmarked page?

Think of it from the user's perspective. If they just get that vague HTTP 403 error, it could be a bit jolting for them. Maybe they think "Why is this site broken? I don't trust it, they're always just deleting stuff."

We can do better and say something like, "This job posting has expired and so it's no longer available". Now we're giving them useful information. Maybe they didn't even know job postings expire. This information can encourage the user to move faster because they now know that things expire.

Validation errors are part of the user experience and deserve some consideration.

Here to help,

Joel

P.S. We offer country-specific discounts to make the book more affordable.

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.