I have validated the exception when people input the leave_from_date and leave_to_date that contains blocked day, but when i change to the new date, i cant add a new LeaveRequest. This is my code from LeaveRepository
public function create($inputs){
$events = DB::table('events')
->where('event_type_id', 2)
->get();
$from_dates = $inputs['leave_from_date'];
$to_dates = $inputs['leave_to_date'];
//foreach cái mảng
foreach ($events as $event) {
foreach ($from_dates as $key => $from_date) {
if (($from_date >= $event->from_date && $from_date <= $event->to_date)
|| ($to_dates[$key] >= $event->from_date && $to_dates[$key] <= $event->to_date)) {
return false;
}
}
}
return $this->model->create(request()->all());
}
I also when testing with postman, i can only use Form-data with leave_from_date[] and leave_to_date[] like this. It is inconvenient for me. Is there anyway to handle the input better? When i change the leave_from_date and leave_to_date like this in form, it got error
Invalid argument supplied for foreach()
Is there anyway to handle input with validation like this. I have validated success that days contains blocked days will be changed but cannot add. Thank you
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire