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.