F
Filament10mo ago
\

Searching for values in hidden columns

Hey, I have columns in my table that are set as hidden, but I still want to be able to search for values within those columns. I've tried to modify the applySearchToTableQuery() and applyColumnSearchesToTableQuery() methods as per the documentation, but it doesn't seem to work. These functions are located directly above my table function. These functions are located in my EventsResource directly above the table function.
protected function applySearchToTableQuery(Builder $query): Builder
{
$this->applyColumnSearchesToTableQuery($query);

if (filled($search = $this->getTableSearch())) {
$query->whereIn('attendances.employee.name', Event::search($search)->keys());
}

return $query;
}
protected function applySearchToTableQuery(Builder $query): Builder
{
$this->applyColumnSearchesToTableQuery($query);

if (filled($search = $this->getTableSearch())) {
$query->whereIn('attendances.employee.name', Event::search($search)->keys());
}

return $query;
}
protected function applyColumnSearchesToTableQuery(Builder $query): Builder
{
foreach ($this->getTableColumnSearches() as $column => $search) {
if (blank($search)) {
continue;
}

$column = $this->getTable()->getColumn($column);

if (! $column) {
continue;
}

// COMMENTED
//if ($column->isHidden()) {
// continue;
//}

if (! $column->isIndividuallySearchable()) {
continue;
}

foreach ($this->extractTableSearchWords($search) as $searchWord) {
$query->where(function (Builder $query) use ($column, $searchWord) {
$isFirst = true;

$column->applySearchConstraint(
$query,
$searchWord,
$isFirst,
);
});
}
}
}
protected function applyColumnSearchesToTableQuery(Builder $query): Builder
{
foreach ($this->getTableColumnSearches() as $column => $search) {
if (blank($search)) {
continue;
}

$column = $this->getTable()->getColumn($column);

if (! $column) {
continue;
}

// COMMENTED
//if ($column->isHidden()) {
// continue;
//}

if (! $column->isIndividuallySearchable()) {
continue;
}

foreach ($this->extractTableSearchWords($search) as $searchWord) {
$query->where(function (Builder $query) use ($column, $searchWord) {
$isFirst = true;

$column->applySearchConstraint(
$query,
$searchWord,
$isFirst,
);
});
}
}
}
I've attempted some modifications, but it doesn't seem to work. The functions are not even being activated by a search query, as I tested with dd(). Any kind of help would be appreciated
1 Reply
\
\OP10mo ago
The column in question
TextColumn::make('attendances.employee.name')
->hidden()
->searchable(),
TextColumn::make('attendances.employee.name')
->hidden()
->searchable(),
Want results from more Discord servers?
Add your server