F
Filament4mo ago
Wahba

Search records in an Attach Action

Hello everyone, I was wondering if I could be able to search the records generated by $action->getRecordSelect() in an Attach action. I know there is a way to search by specifying the columns, but I want instead to search using a column in a related record instead. Is there a way to modify the query similar to how we can do it in ->searchable() ?
AttachAction::make()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
TextInput::make('quantity')->numeric()
->minValue(1)
->required(),
])
->preloadRecordSelect()
->recordSelectOptionsQuery(function ($query) {
return $query
->where('stock', '>', 0);
})
AttachAction::make()
->form(fn (AttachAction $action): array => [
$action->getRecordSelect(),
TextInput::make('quantity')->numeric()
->minValue(1)
->required(),
])
->preloadRecordSelect()
->recordSelectOptionsQuery(function ($query) {
return $query
->where('stock', '>', 0);
})
Solution:
I actually managed to fix it by this way if anyone has the same issue: ``` ->recordSelect( fn (Select $select) => $select->getSearchResultsUsing(function(string $search): array {...
Jump to solution
1 Reply
Solution
Wahba
Wahba4mo ago
I actually managed to fix it by this way if anyone has the same issue:
->recordSelect(
fn (Select $select) => $select->getSearchResultsUsing(function(string $search): array {
return User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray());
}),
)
->recordSelect(
fn (Select $select) => $select->getSearchResultsUsing(function(string $search): array {
return User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray());
}),
)
Want results from more Discord servers?
Add your server