Я использую полный календарь в своем проекте Laravel, и мне нужно добавить в него повторяющиеся события.
Я добавил флажки в своем пользовательском интерфейсе, которые представляют каждый день недели (понедельник, вторник,ср.).
В полном календаре я добавил свойство daysofweek
.
В основном:
Дни недели, в которыесобытие будет повторяться (это массив целых чисел).
Каждое целое представляет день недели, где 0 означает воскресенье, 1 означает понедельник и т. д. (например,[2, 4] означает, что событие повторяется каждый вторник и четверг).
Если не указано, предполагается, что событие будет повторяться каждый день.
Я хочу нажать на понедельник, и к массиву будет добавлено целое число, как в примере ниже:
$event_dow = [1];
Если я нажму и в понедельник, и во вторник, массив будет иметь:
$event_dow = [1,2];
Понятия не имею, как это сделать.
Следуйте ниже моего кода:
EventController.php
public function store(Request $request)
{
//
$this->validate($request, [
'event_name' => 'required|string|min:2|max:255',
'daterange' => 'required',
]);
$time_start = $request->input('start_time');
$time_end = $request->input('end_time');
$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]);
$event_dow = [];
if($request->has('monCheck'))
{
$$event_dow = $event_dow.'1';
};
if($request->has('tueCheck'))
{
$event_dow = $event_dow.'2';
};
if($request->has('wedCheck'))
{
$event_dow = $event_dow.'3';
};
if($request->has('thurCheck'))
{
$event_dow = $event_dow.'4';
};
if($request->has('friCheck'))
{
$event_dow = $event_dow.'5';
};
if($request->has('satCheck'))
{
$event_dow = $event_dow.'6';
};
if($request->has('sunCheck'))
{
$event_dow = $event_dow.'7';
};
$event = new event([
'event_name' => $request->input('event_name'),
'event_desc' => $request->input('event_desc'),
'event_venue' => $request->input('event_venue'),
'event_start' => date_format($date1, 'Y-m-d H:i:s'),
'event_finish' => date_format($date2, 'Y-m-d H:i:s'),
'event_venue' => $request->input('event_venue'),
'event_dow' => $request->input('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');
}
пилка
<div class="row" style="margin-left: 50px;">
<div class="form-check form-check-inline">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="monCheck" id="monCheck">
<label class="custom-control-label" for="monCheck">Mon</label>
</div>
</div>
<div class="form-check form-check-inline">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="tueCheck" id="tueCheck">
<label class="custom-control-label" for="tueCheck">Tue</label>
</div>
</div>
<div class="form-check form-check-inline">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="wedCheck" id="wedCheck">
<label class="custom-control-label" for="wedCheck">Wed</label>
</div>
</div>
<div class="form-check form-check-inline">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="thurCheck" id="thurCheck">
<label class="custom-control-label" for="thurCheck">Th</label>
</div>
</div>
<div class="form-check form-check-inline">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="friCheck" id="friCheck">
<label class="custom-control-label" for="friCheck">Fri</label>
</div>
</div>
<div class="form-check form-check-inline">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="satCheck" id="satCheck">
<label class="custom-control-label" for="satCheck">Sat</label>
</div>
</div>
<div class="form-check form-check-inline">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="sunCheck" id="sunCheck">
<label class="custom-control-label" for="sunCheck">Sun</label>
</div>
</div>
</div>