Я использую Laravel -5,8 и jQuery -fullcalendar для Leavel Application:
Контроллер
public function index()
{
try {
$userCompany = Auth::user()->company_id;
$userID = Auth::user()->id;
$userEmployee = Auth::user()->employee_id;
$leaverequests = HrLeaveRequest::where('employee_id', $userEmployee)->where('company_id', $userCompany)->whereYear('created_at', date('Y'))->get();
return view('service.leave_requests.index')->with('leaverequests', $leaverequests);
} catch (Exception $exception) {
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
index.blade
<div class="card-body p-0">
<div id='calendar'></div>
</div>
@section('javascript')
<script src="{{ asset('theme/adminlte3/plugins/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('theme/adminlte3/plugins/moment/moment.min.js') }}"></script>
<script src="{{ asset('theme/adminlte3/plugins/jquery-fullcalendar/fullcalendar.min.js') }}"></script>
<script src="{{ asset('theme/adminlte3/plugins/jquery-ui/jquery-ui.min.js') }}"></script>
<script>
$(document).ready(function () {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
header: {
left: 'prev,next,today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
events : [
@foreach($leaverequests as $leaverequest)
{
title : '{{ $leaverequest->leavetype->leave_type_name }}',
fullname : '{{ $leaverequest->employee->first_name . ' ' . $leaverequest->employee->last_name }}',
start : '{{ Carbon\Carbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}',
end: '{{ Carbon\Carbon::parse($leaverequest->resumption_date)->format('d-m-Y') ?? '' }}',
url : '{{ route('service.leave_requests.edit', $leaverequest->id) }}'
},
@endforeach
]
})
});
</script>
@stop
Когда Я отобразил страницу, я получил эту ошибку:
moment.min.js:1 Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: 11-04-2020, _f: undefined, _strict: undefined, _locale: [object Object]
Error
at Function.createFromInputFallback (http://localhost:8888/adminlte3/plugins/moment/moment.min.js:1:3368)
at Ot (http://localhost:8888/adminlte3/plugins/moment/moment.min.js:1:21539)
at Tt (http://localhost:8888/adminlte3/plugins/moment/moment.min.js:1:22250)
at Function.y [as utc] (http://localhost:8888/adminlte3/plugins/moment/moment.min.js:1:935)
at i (http://localhost:8888/adminlte3/plugins/jquery-fullcalendar/fullcalendar.min.js:6:15257)
at h.parseZone (http://localhost:8888/adminlte3/plugins/jquery-fullcalendar/fullcalendar.min.js:6:15903)
at t.moment (http://localhost:8888/adminlte3/plugins/jquery-fullcalendar/fullcalendar.min.js:10:31801)
at Function.t.parse (http://localhost:8888/adminlte3/plugins/jquery-fullcalendar/fullcalendar.min.js:6:19409)
at e.applyManualStandardProps (http://localhost:8888/adminlte3/plugins/jquery-fullcalendar/fullcalendar.min.js:6:14719)
at e.applyProps (http://localhost:8888/adminlte3/plugins/jquery-fullcalendar/fullcalendar.min.js:8:11549)
Когда я удалил этот код:
start : '{{ Carbon\Carbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}',
end: '{{ Carbon\Carbon::parse($leaverequest->resumption_date)->format('d-m-Y') ?? '' }}',
из скрипта #calendar, ошибка исчезла, но в календаре ничего не появилось .
Как заставить календарь работать с этим кодом?
start : '{{ Carbon\Carbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}',
end: '{{ Carbon\Carbon::parse($leaverequest->resumption_date)->format('d-m-Y') ?? '' }}',
Спасибо