samedi 6 juin 2020

laravel validation with condition on a specific column

i want to make a field unique but only with a condition the field start_date in my event table should be unique only if the pitch_id is the same to clarify a reservation start date can be the same date if the pitch is not the same i mean if the start date and the pitch id are unique it should not pass

here's my code

public function store(Request $request)
    {    
        $this -> validate($request ,[

        'start_date' => ['unique:reservations'],

]);
        $events = new Reservation();
        $events->type = $request->get('type');
        $events->start_date = $request->get('start_date');
        $events->end_date = $request->get('end_date');
        $events->pitch_id = $request->input('pitch_id');
        $events->save();
        return redirect('Reservations')->with('success', 'réservation crée avec succès');
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire