In Laravel 5.3, I'm trying to catch if an uploaded file has a bigger file size than upload\_max\_filesize. The upload field is not required.

I tried this method, but it doesn't work

```
public function checkFile($field)
{
    if (request()->hasFile($field)){ // check if field is present
        $file = request()->file($field);
        if (!$file->isValid()){ // now check if it's valid
            return back()->with('error', $file->getErrorMessage());
        }
    }
}

```

I can't use just `if (!$file->isValid())` because file field is optional and i get a `Call to a member function isValid() on null` if field is empty.

So I have to check if field is present using `if (request()->hasFile($field))`, but this doesn't work for big files, since `dd(request()->hasFile('picture'))` returns `false`.

Of course I can rely on default Laravel Validator messages, but I get a dummy `The picture failed to upload.` that doesn't give any clue to the user.