Table Filter isn't working (I'll have a topic for each of these soon apparently =/)
Created 7 years ago by edsterSigh, here I go again.
Trying to get a table filter to work after following the guide on the site. I tried tweaking things around, I'm GUESSING my handler is fucked up? But if I DD in the handle function, it doesn't trigger, so I don't know what I did wrong.
Here is what I have
Table collection contains the following sets of data.
$tableData = collect();
$buildings = Auth::user()->buildings()->get();
// Push the data to a collection to use in the table builder
foreach ($buildings as $building) {
foreach ($building->documents as $document){
$tableData->push([
'document_name' => $document->name,
'building_name' => $building->name,
'building_address' => $building->address['formatted'],
'document' => $document
]);
}
}
//Push it to the table builder
$table->setTableEntries($tableData);
//Render the table
return $table->render();
My table columns
$builder->setColumns([
'entry.document_name' =>[
'heading' => 'Document Name'
],
[
'sort_column' => 'file_date',
'heading' => 'File Date',
'value' => function ($entry) {
return $entry['document']->updated_at == NULL ? $entry['document']->created_at->format('Y-m-d') : $entry['document']->updated_at->format('Y-m-d');
}
],
'entry.building_name' => [
'heading' => 'Building'
],
'entry.building_address'=> [
'heading' => 'Building Address'
]
]);
My beautiful filter that refuses to work
public function handle(DocumentTableBuilder $builder)
{
$builder->setFilters([
'building_name' => [
'filter' => 'input',
'query' => DocumentTableBuildingFilter::class,
'placeholder' => 'Building Number',
],
]);
}
And the handler
public function handle(Builder $query, FilterInterface $filter)
{
$query->where($filter->getSlug(), 'LIKE', "%{$filter->getValue()}%");
}
ryanthompson
—
7 years ago
I don’t see any reason you need to set entries manually. Usually you only run into that when you are using non-models. Like an API response for example.
Try using the onQuerying
callback to do your auth restriction using where
on the provided Builder $query
.
Hmmm.. filters don't run when you set the table entries manually.