You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, @yajra ,
I'm sorry to bother you, but this issue is very confusing.
I'm implementing caching using Redis to cache my query. When I display all the data, it works perfectly.
However, the error occurs when I apply any of the manual filters I've created. It returns the following exception:
Exception Message: Method Yajra\DataTables\CollectionDataTable::where does not exist.
This is very strange because when I don't use caching, the query works perfectly.
Please helpppp
Code snippet of problem
here is the preview for some of my codes.
Controller.php
publicfunctionindex(Request$request)
{
if ($request->ajax()) {
$query = Cache::remember('dayoff_all_datas', 1800, function () {
$data = Dayoff::with('pegawaiRelasi:kode_pegawai,full_name');
if (!Auth::user()->can('dayoff-confirm')) {
$data->where('kode_pegawai', Auth::user()->kode_pegawai);
}
return$data->get(); // Do not call ->get() here
});
// Pass the query to DataTables::eloquentreturn DataTables::of($query)
->addIndexColumn()
// Some columns using rendered blade templating
->filter(function ($query) use ($request) {
if ($request->filled("dayoff_for")) {
$query->where('dayoff_for', "=", $request->dayoff_for);
}
if ($request->filled("kode_pegawai")) {
$query->where('kode_pegawai', "LIKE", "%{$request->kode_pegawai}%");
}
if ($request->filled("status")) {
$query->where('status', "=", $request->status);
}
if ($request->filled("startDate") && $request->filled("endDate")) {
$query->whereBetween('created_at', [$request->startDate, $request->endDate]);
}
})
// ->orderColumn('created_at', '-created_at $1')
->rawColumns(['status', 'kode_pegawai', 'created_at', 'tgl_dari', 'actions'])
->toJson();
}
returnview('dashboard.dayoff.index');
}
js/collect/showData.js
exportfunctionshowDatatables(){// Initialize DataTablelettable=$('#table-dayoff').DataTable({processing: true,serverSide: true,responsive: true,"lengthMenu": [15,25,50,75,100,-1],ajax: {url: dayoffIndex,data: function(d){d.dayoff_for=$('#dayoff-for').val();d.kode_pegawai=$('#kode-pegawai').val();d.status=$('#status').val();d.startDate=$('#datepicker-range-start').val();d.endDate=$('#datepicker-range-end').val();}},columns: [// some columns],// some configuration});$('#cari').click(function(){// get value from input filtersconstfilters=['#dayoff-for','#kode-pegawai','#status','#datepicker-range-start','#datepicker-range-end'].map(selector=>$(selector).val());// cek if the value is nullif(filters.some(value=>value!=='')){table.draw();}});// if clear button clicked$('#clear').click(function(){// get all value from input filterconstfilters=['#dayoff-for','#kode-pegawai','#status','#datepicker-range-start','#datepicker-range-end'].map(selector=>$(selector).val());// check if filter is nullif(filters.some(value=>value!=='')){// nullify all the values$('#dayoff-for').val('');$('#kode-pegawai').val('');$('#status').prop('selectedIndex',0);$('#datepicker-range-start').val('');$('#datepicker-range-end').val('');table.draw();}});}
here's some pics: datatables can show all of the data
but if i select to filter
it will give me the error like this:
System details
Operating System: Windows 11 Pro 23H2
PHP Version: PHP 8.2.22 NTS
Laravel Version: Laravel 11.36
Laravel-Datatables Version: 11
The text was updated successfully, but these errors were encountered:
Summary of problem or feature request
Hello, @yajra ,
I'm sorry to bother you, but this issue is very confusing.
I'm implementing caching using Redis to cache my query. When I display all the data, it works perfectly.
However, the error occurs when I apply any of the manual filters I've created. It returns the following exception:
Exception Message: Method Yajra\DataTables\CollectionDataTable::where does not exist.
This is very strange because when I don't use caching, the query works perfectly.
Please helpppp
Code snippet of problem
here is the preview for some of my codes.
Controller.php
js/collect/showData.js
here's some pics:
datatables can show all of the data
but if i select to filter
it will give me the error like this:
System details
The text was updated successfully, but these errors were encountered: