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();
    }


And each CustomOptionType belongs to CustomOption -

  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 -
`php 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.
Was this page helpful?