Data missing error when using Carbon::createFromFormat in laravel [dateFormat: year-month]

  ajax, laravel, pdf, php-carbon

I’m getting "Data Missing" error when using Carbon to pass data to pdf view in Laravel.
The query work when the data is pass back to the same page with dropdown list but getting error when pass to another page.

the error that i get
enter image description here

I’m using date picker as my dropdown list & the date format that I’m using is:
"2020-December"

ajax:

                changeMonth:true,
                changeYear:true,
                showButtonPanel:true,
                dateFormat: "yy-MM",
 
            onClose: function(dateText, inst) {  
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
                $(this).datepicker('setDate', new Date(year, month, 1)); 
              }
            });

 $('#convertBtn').click(function() {     
                var s = document.getElementById("sites");
                var site = s.options[s.selectedIndex].text;
                var startdate = $('#datepicker-8').val();

            if(site != '' && startdate  != '' )
            {  
                $.ajax({ 
                    paging: false,
                    searching: false, 
                    processing: true,
                    retrieve: true,
                    serverSide: true,
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    url:"{{ route('billing.bill') }}",
                    type:"GET",
                    dataType:"json",
                    data:{
                        site:site, 
                        startdate:startdate,
                        },
                    
                    success:function(data){
                     alert(JSON.stringify(data));
                     
                    },
                    error: function(data){
                        alert('Error');
                    }
                }) 
            } 
            else
            {
                alert("Please select 'Site' & 'Date'. ");
            }
        });

controller

$sites['report_date'] = Carbon::createFromFormat('Y-F', $request->startdate);
        $data = DB::table('monthly_data')
                ->where('site', $request->site)
                ->whereMonth('report_date', $sites['report_date'])
                ->whereYear('report_date',$sites['report_date'])
                ->get();

        $pdf = App::make('dompdf.wrapper');
        $pdf -> loadView('pdf',compact('data'));
        $pdf -> setPaper('a4','landscape');
        return $pdf->stream('report.pdf');

may i know how to solve this error?

Source: Laravel

Leave a Reply