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);
    })
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 {
        return User::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray());
    }),
    )
Was this page helpful?