Can't use $get inside recordSelectOptionsQuery: any workaround?

Hi, I didn't find the answer on this discord, nor in the docs. What I'm trying to do: Modify the query of the attach action select based on another field The code:
Tables\Actions\AttachAction::make()
->form(function (AttachAction $action): array {
return [

// The field I want to get...
Forms\Components\Toggle::make('mine_only')
->live()
->dehydrated(false),

$action->getRecordSelect(),
];
})
->recordSelectOptionsQuery(
function (Builder $query, $livewire, $get) {

dd($livewire); // Works but I don't know if I can "get" from this

dd($get('mine_only')); // Doesn't work: (An attempt was made to evaluate a closure for [Filament\Tables\Actions\AttachAction], but [$get] was unresolvable.)

// This should be returned if Toggle is on
return $query->whereHas('users',
fn(Builder $query) => $query->where('users.id', auth()->user()->id)
);

// Else if Toggle is off return the base query
return $query;
}
)
Tables\Actions\AttachAction::make()
->form(function (AttachAction $action): array {
return [

// The field I want to get...
Forms\Components\Toggle::make('mine_only')
->live()
->dehydrated(false),

$action->getRecordSelect(),
];
})
->recordSelectOptionsQuery(
function (Builder $query, $livewire, $get) {

dd($livewire); // Works but I don't know if I can "get" from this

dd($get('mine_only')); // Doesn't work: (An attempt was made to evaluate a closure for [Filament\Tables\Actions\AttachAction], but [$get] was unresolvable.)

// This should be returned if Toggle is on
return $query->whereHas('users',
fn(Builder $query) => $query->where('users.id', auth()->user()->id)
);

// Else if Toggle is off return the base query
return $query;
}
)
Thanks for the help!
3 Replies
toeknee
toeknee2mo ago
Try $data on the function to the right of builder and did that
charlie
charlieOP2mo ago
Hi, not sure what you mean, but if I do it like that, $data returns an empty array:
->recordSelectOptionsQuery(
function (Builder $query, $livewire, $data) {
dump($data); // returns []
// ...
}
)
->recordSelectOptionsQuery(
function (Builder $query, $livewire, $data) {
dump($data); // returns []
// ...
}
)
Dennis Koch
Dennis Koch2mo ago
Instead of using recordSelectOptionsQuery() try overriding the whole Select (probably recordSelect()?) and use $get for getSearchResultsUsing()
Want results from more Discord servers?
Add your server