我正在使用Laravel-5.8和jQuery fullcalendar用于Leavel应用程序:
控制器
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刀片
<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 : '{{ CarbonCarbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}',
end: '{{ CarbonCarbon::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 : '{{ CarbonCarbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}',
end: '{{ CarbonCarbon::parse($leaverequest->resumption_date)->format('d-m-Y') ?? '' }}',
从#calendar脚本中,错误消失了,但日历上没有显示任何内容。
我如何让日历工作仍然放这个代码?
start : '{{ CarbonCarbon::parse($leaverequest->commencement_date)->format('d-m-Y') ?? '' }}',
end: '{{ CarbonCarbon::parse($leaverequest->resumption_date)->format('d-m-Y') ?? '' }}',
谢谢
这不是一个错误,它只是一个警告,它告诉您在下一次momentjs
更新中不再支持什么。
您可以通过执行警告中所说的操作来轻松解决此问题:提供RFC2822或ISO日期。
CarbonCarbon::parse($leaverequest->commencement_date)->toRfc2822String()
或
CarbonCarbon::parse($leaverequest->commencement_date)->toISOString()
有关碳的更多信息,请查看文档:https://carbon.nesbot.com/docs