I have a massive dataset so pagination is essential.
Following the excellent videos on datatables by Caleb, I have the following working query/pagination combo:
public function getRowsQueryProperty()
{
$query = PartMaster::query()
->when($this->filters['cat'], fn($query) => $query->where('cat', $this->filters['cat']))
->when($this->filters['eu'], fn($query) => $query->where('eu', $this->filters['eu']))
->when($this->filters['description'], fn($query) => $query->where('description', 'like', '%'.$this->filters['description'].'%'))
->when($this->filters['variance'], fn($query) => $query->where('variance'))
->when($this->filters['repair'], fn($query) => $query->where('should_repair'))
->when($this->filters['performer'], fn($query) => $query->where('top_performer'))
->when($this->filters['amount-min'], fn($query, $amount) => $query->where('model_value', '>=', $amount))
->when($this->filters['amount-max'], fn($query, $amount) => $query->where('model_value', '<=', $amount))
->when($this->filters['search'], fn($query) => $query->where('part_number', 'like', '%'.$this->filters['search'].'%'));
return $this->applySorting($query);
} // end function
public function getRowsProperty()
{
// if($this->filters['overdue']) {
//return $this->rowsQuery->filter(function($i){
// return $i->overdue;
//})->paginate($this->perPage);
//} else {
return $this->cache(function () {
return $this->rowsQuery->paginate($this->perPage);
});
//} // end if
} // end function
In the getRowsProperty I am trying to further filter the results (I think I have to do it here because overdue is an mutator value and not a database column). If I uncomment those lines, I get the Call to undefined method Illuminate\Database\Eloquent\Builder::filter() which makes sense since it isn't a collection.
BUT I don't know how to use that mutator to limit the rows.