Laravel,如果请求不为null,则检查条件

I have a form in Laravel and the submission and validation works, but I'm doing custom validation to check the data against the database (for sanitization) as well.

The issue is, I only want to do this validation IF each of the fields is filled out. In other words, if an input isn't required thus not filled out, I don't want it to fail because of it not matching data in the database.

For instance, I have a form input on my blade:

<td>{!! Form::select('productNumber',  $img->productNumber) !!}</td>

and in the controller I'm checking this against the service to make sure it's valid data

if(!$productCheckService->validGroupCode($request->productNumber))
        return back()->withErrors("Invalid group: ".$request->productNumber);

This works if filled out, but if the field is empty I want to bypass that check. In other words, the field isn't required so the data validity check shouldn't be required on a possibly null/empty field

I'm doing this below but it still is failing if it's empty for some reason. Am I totally missing something? I would think that checking that it's not empty before the check should suffice.

if(!empty($request->productNumber))
 if(!$productCheckService->validGroupCode($request->productNumber))
        return back()->withErrors("Invalid group: ".$request->productNumber);

You can use Laravel 'sometimes' attributes, so if your field is not present in request array it will bypass from validation.

$v = Validator::make($data, [
'productNumber' => 'sometimes|required|number',

]);