samedi 11 novembre 2017

laravel 5.4 validate array with custom rule

I'm having trouble validating an array of fields that requires a custom rule. I have the following validator:

$validator = Validator::make($request->all(), [
     'order'        => 'required',
     'service_id.*' => Rule::unique('order_services')->where('order_id', $request->order),
     'due_date.*'   => 'required|date',
     'vendor'   => 'required|integer',
     'instructions' => 'string|nullable',
     'lock_box' => 'string|nullable',
  ]);

The due date array validates just fine, but the service id returns the following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'service_id.0' in 'where clause' (SQL: select count(*) as aggregate from `order_services` where `service_id`.`0` = 10 and `order_id` = 100f)

The service id rule prevents duplicate records with the same order number and service id

The rule works as expected when validating a single service ID, I'm just not sure how to validate multiple service IDs at the same time.

Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AuvLYL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire