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');
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3gSFLRs
via IFTTT
Aucun commentaire:
Enregistrer un commentaire