簡體   English   中英

Laravel - 棄用警告:提供的值不是可識別的 RFC2822 或 ISO 格式

[英]Laravel - Deprecation warning: value provided is not in a recognized RFC2822 or ISO format

我將 Laravel-5.8 和 jQuery-fullcalendar 用於 Leavel 應用程序:

Controller

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();
        }           
}

索引刀片

   <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') ?? '' }}',

謝謝

這不是錯誤,它只是一個警告,它會告訴您下一個momentjs更新中不再支持的內容。

您可以按照警告中的說明輕松解決此問題:提供 RFC2822 或 ISO 日期。

Carbon\Carbon::parse($leaverequest->commencement_date)->toRfc2822String()

或者

Carbon\Carbon::parse($leaverequest->commencement_date)->toISOString()

有關碳的更多信息,請查看文檔: https://carbon.nesbot.com/docs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM