tl;dr
Upgrade to Laravel 5.5 or higher. They changed this so now it works as you originally expected.
Explanation
In the Laravel 5.5 upgrade guide, we read the following:
The
has
Method
The
$request->has()
method will now returntrue
even if the input value is an empty string ornull
. A new$request->filled()
method has been added that provides the previous behaviour of thehas()
method.
The $request->exists()
method still works, it is just an alias for $request->has()
.
Examining the source code
- In Laravel 5.4:
$request->exists()
: Determine if the request contains a given input item key.$request->has()
: Determine if the request contains a non-empty value for an input item.- In Laravel 5.5:
$request->exists()
: Alias for$request->has
$request->has()
: Determine if the request contains a given input item key.$request->filled()
: Determine if the request contains a non-empty value for an input item.
If you click to the commands above, you can check out the source code and see that they literally just renamed exists
to has
, has
to filled
, then aliased exists
to has
.