mardi 25 septembre 2018

Validating an array of objects in Laravel

I have these validation rules in Laravel 5.7 form request class. First 4 lines works as intended. The last line doesn't.

'service_type' => 'required|alpha',
'trips.*.pu_location' => 'required_if:service_type,transfer,multi|string|nullable',
'trips.*.pu_address' => 'required_if:service_type,transfer,multi|string|nullable',
'trips.*.pu_location_code' => 'required|string|max:7',
'trips.*.pu_airline' => 'required_if:pu_location_code,AIRPORT'

My controller:

$reservation = $user->reservations()->create([
    ...
    'service' => $request->service_type,
    ...
]);

foreach ($request->trips as $trip) {
    $reservationTrips[] = $trip;
}

$reservation->trips()->createMany($reservationTrips);

Any ideas why this is happening?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire