logo
podcast Podcast
get help Get Unstuck

Why the nullable validation rule is useful

Sometimes code is for your team, not just the PHP runtime

Joel Clermont
Joel Clermont
2023-12-20

Here's a fun fact to consider: It is impossible to make the nullable validation rule fail in Laravel. There is literally no data you can provide that will fail that rule. As a result, it's the one rule I can't write a test for.

So why is it useful? It's similar to the point I made earlier this week about using the mixed type. It's an explicit definition that lets you express clear intent in your rules.

Specifying nullable for a field makes it clear you actually intend it to be nullable. Without specifying it, someone could wonder if you just forgot to put required or present in that field's rule instead.

Here to help,

Joel

P.S. How confident are you in your app's validation rules? We've assembled a comprehensive guide to getting the most out of your validation logic.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.