in php we can do
isset($_POST['name'])
so that user submit empty text can be detected.
but in laravel
$request->has('name')
return null on empty string too.
I need to find a way to tell if it is an empty string or the field not posted at all
If you're using laravel 5.4 or above, by default it uses a middleware to convert all empty strings to null.
In App\Http\Kernel.php:
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class
Comment out this middleware to prevent this behaviour.
You can use exists() method in request instance. If you want to check if there is value in request check:
$request->has('key');
if you want to check if the key is exists use:
$request->exists('key');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With