F
Filament10mo ago
prowler

Grouping by parent in a Select component

I have a 3 models - Brief, CustomOption and CustomOptionType. Each Brief belongs to many CustomOptionType with a pivot table -
public function customOptionTypes(): BelongsToMany
{
return $this->belongsToMany(CustomOptionType::class, 'brief_custom_option_types', 'brief_id', 'custom_option_type_id')
->withTimestamps();
}
public function customOptionTypes(): BelongsToMany
{
return $this->belongsToMany(CustomOptionType::class, 'brief_custom_option_types', 'brief_id', 'custom_option_type_id')
->withTimestamps();
}
And each CustomOptionType belongs to CustomOption -
public function customOption(): BelongsTo
{
return $this->belongsTo(CustomOption::class);
}
public function customOption(): BelongsTo
{
return $this->belongsTo(CustomOption::class);
}
Now, in BriefResource.php - I'd like to group this Select component by the 'parents' of the custom option types -
Select::make('Custom Options')
->label('Custom Options')
->preload()
->searchable()
->relationship('customOptionTypes', 'name')
->multiple(),
Select::make('Custom Options')
->label('Custom Options')
->preload()
->searchable()
->relationship('customOptionTypes', 'name')
->multiple(),
I know you can group them when explicitly using the ->options() function, but in this case im loading those directly via a relationship so im not sure how to achieve that. Thanks in advance.
4 Replies
Dan Harrin
Dan Harrin10mo ago
you will need to override the options() etc to group them
prowler
prowlerOP10mo ago
yes, but in my case the options are being loaded automatically due to the ->relationship() function
krekas
krekas10mo ago
i would guess you should generate options manually in this case

Did you find this page helpful?