For my project I am using laravel and also used fullcalendar to display the events I made I have already made the code to add and update event details.
What I want to know is how can I add an event and also make sure that that specific timeslot is available and it won't cause conflict with another event?
My EventController.php
public function ajaxget(){
$ev = event::select('id as id', 'event_name as title', 'event_start as start', 'event_finish as end', 'event_dow as dow')->where('user_id', Auth::user()->id)->get();
// Return as json
return response()->json($ev);
}
public function store(Request $request)
{
//dd($request);
$this->validate($request, [
'event_name' => 'required|string|min:2|max:255',
'daterange' => 'required',
]);
$tempDate = $request->input('daterange');
$temp2 = str_replace('-', null, $tempDate);
$temp2 = str_replace('/', '-', $temp2);
$temp3 = explode(' ', $temp2);
$date1 = date_create_from_format('m-d-Y', $temp3[0]);
$date2 = date_create_from_format('m-d-Y', $temp3[1]);
$tempdate1 = date_format($date1, 'Y-m-d');
$tempdate2 = date_format($date2, 'Y-m-d');
$time_start = $request->input('start_time');
$time_end = $request->input('end_time');
$combinedDT1 = date('Y-m-d H:i:s', strtotime("$tempdate1 $time_start"));
$combinedDT2 = date('Y-m-d H:i:s', strtotime("$tempdate2 $time_end"));
$event_dow = [];
if($request->has('monCheck'))
{
$event_dow[] = (int)$request->monCheck;
};
if($request->has('tueCheck'))
{
$event_dow[] = (int)$request->tueCheck;
};
if($request->has('wedCheck'))
{
$event_dow[] = (int)$request->wedCheck;
};
if($request->has('thurCheck'))
{
$event_dow[] = (int)$request->thurCheck;
};
if($request->has('friCheck'))
{
$event_dow[] = (int)$request->friCheck;
};
if($request->has('satCheck'))
{
$event_dow[] = (int)$request->satCheck;
};
if($request->has('sunCheck'))
{
$event_dow[] = (int)$request->sunCheck;
};
//$eventDow = implode(',', $event_dow);
$event = new event([
'event_name' => $request->input('event_name'),
'event_desc' => $request->input('event_desc'),
'event_venue' => $request->input('event_venue'),
'event_start' => $combinedDT1,
'event_finish' => $combinedDT2,
'event_dow' => $event_dow, //days of week
'evcat_id' => $request->input('evcat_id'),
'user_id' => $request->input('user_id')
]);
$event->save();
Session::flash('success', 'Event Created Successfully');
return redirect()->route('event.sched');
}
I want to avoid instances such as these that have 2 events that clash with each others schedules.
via Chebli Mohamed


Aucun commentaire:
Enregistrer un commentaire