好吧,事实证明--
if($request->foobar == ''){
// this passes
}
if($request->foobar === ''){
// but this doesn't (note the strict '===' operator)
}
这是因为请求值实际上是
null
:
if(is_null($request->foobar)){
// yes, passes
}
原因如下:Laravel 5.4+使用
ConvertEmptyStringsToNull
默认情况下使用中间件。请参阅内核。php:
protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, // this one
];
幸亏
this answer
为我指明了正确的方向。