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
Nuekrato2mo 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
awcodes2mo ago
Options and relationship don’t work together. One will always override the other.
Nuekrato
Nuekrato2mo 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
More Posts
Best Practices for Websites with FilamentPHPNow that I understand how to use FilamentPHP for creating apps and backends, I need to create the frRelationship Manager for BelongsTo and HasMany RelationshipWhat I am trying to do: I have a Relationship between Users and Domains. I want to create a Relationcreate a Order in my orderline page i get a error that the method is undefinedwhen i create a OrderLine and then edit it and make a Order (inside the orderline) i get this error how to show a MorphOne table in filament Table?I am struggling to access MorphOne relationship data in my table. I have Member model with MorphOne Section Heading-Background-ColorHi - Is it possible to change the background-color of a section-heading? I already tried the `extraAExecute filament commands inside a filament pluginHi, I am making a filament plugin which includes resources, models, relationmanagers, etc... Is theIs there a method to disable select row (checkbox) and display just the table with actions, filtersCurrently i'm hiding the checkbox prefixed with each row with css but is there an offical way to remexport notification message doesn't change base on localeAs we can see from image, I have translation file in `action/km/export` but on the notification listMultiple Modal IssueI stumbled upon an issue where I have multiple actions(opening modals). Whenever I open a modal, cloSQLSTATE[IMSSP]: Field 34 returned no data.Currently, I am facing an issue in displaying data from SQL Server. Why am I encountering an error l