CheckboxList: modifyOptionsQueryUsing does not exist

The docs say there should be this method to modify the options but this method does not exist: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list#customizing-the-relationship-query I currently need to accomplish exactly that: Set the relationship based on a different table than the options. Example code:
private function getPermissionsForm()
{
$checkboxLists = [];
foreach ($this->template->allowedTargets as $target) {
$checkboxLists[] = CheckboxList::make('templatePermissions')
->label($target->name)
->relationship(
name: 'templatePermissions',
titleAttribute: 'name',
modifyQueryUsing: fn (Builder $query) => $query->where('template_id', $this->template->id),
)
->options(function () use ($target) {
$permissions = [];
$templatePermissions = Permission::whereNull('model_id')->where('model_type', Project::class)
->where('destination_id', $target->id)->whereIn('name', ['download', 'upload'])->get();
foreach ($templatePermissions as $permission) {
$permissions[$permission->id] = $permission->name;
}
return $permissions;
})
->pivotData([
'template_id' => $this->template->id,
]);
}
return $checkboxLists;
}
private function getPermissionsForm()
{
$checkboxLists = [];
foreach ($this->template->allowedTargets as $target) {
$checkboxLists[] = CheckboxList::make('templatePermissions')
->label($target->name)
->relationship(
name: 'templatePermissions',
titleAttribute: 'name',
modifyQueryUsing: fn (Builder $query) => $query->where('template_id', $this->template->id),
)
->options(function () use ($target) {
$permissions = [];
$templatePermissions = Permission::whereNull('model_id')->where('model_type', Project::class)
->where('destination_id', $target->id)->whereIn('name', ['download', 'upload'])->get();
foreach ($templatePermissions as $permission) {
$permissions[$permission->id] = $permission->name;
}
return $permissions;
})
->pivotData([
'template_id' => $this->template->id,
]);
}
return $checkboxLists;
}
This code is inside a GroupRelationManager of a Template. A Group can belong to templatePermissions (which is the name of the relationship of the group) - but the options are coming from another table. Using the CheckboxList like this gives a wrong result. Also the modifyQueryUsing-method is not called as long as options is set. If I comment out ->options(...) the modifyQueryUsing is called.
3 Replies
Nuekrato
NuekratoOP6mo ago
Does anyone has an idea? This seems like a bug, because it behaves differently than other components - also the missing method from the docs seems odd.
awcodes
awcodes6mo ago
Options and relationship don’t work together. One will always override the other.
Nuekrato
NuekratoOP6mo ago
So I need to use either one and in my use case I think I need options and I should handle the relationship attach/detach myself in the action handle method?
Want results from more Discord servers?
Add your server