How much detail should you include in error messages?


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,


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

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼

Level up your Laravel skills!

Each 2-minute email has real-world advice you can use.