V
V
Vanya Huk2017-06-23 18:47:37
Laravel
Vanya Huk, 2017-06-23 18:47:37

How to check only if the parameter is present?

There is a code

$validator = Validator::make( $this -> request, array(

            'fio'	         => 'required',

            'city'		     => 'required',

            'phone'			 => 'required',

            'delivery_id'    => 'required|integer|exists:deliveries,id',

            'payment_id'     => 'required|integer|exists:payments,id',

            'warehouse'      => 'required'
        )
        );

        if ($validator->fails())
            return response()->json($validator->messages(), env('AJAX_ERROR') );

where $this -> request is an array with parameters, but there may not be a warehouse parameter , when it is not there, it is necessary for the validator to skip it, how to correctly organize this task?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2017-06-23
@vanyahuk

remove required, it will no longer be required

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question