1

I'd like to customize the attach select that is shown when I attach a resource to a course.

The model to attach to has a relation to a related table (like a category of the resource).

Table COURSE ...

Table COURSE_RESOURCE
course_id
resource_id

Table RESOURCE
resource_name
resource_type_id
...

Table RESOURCE_TYPE
resource_type

When attaching a resource to a course with the relationManager, I'd like to be able to use the select to filter on both the resource_name AND the resource_type. Or at least showing the resource_type with the resource_name and not only the resource_name.

The issue is that I have multiple same resource_name that have different resource_type. Right now, I could search by resource_name and their are all showed but I can tell which select option is related to which resource_type.

I try this (where resourceType is the eloquent model relation belongsTo between the 2 tables resource && resource_type)

AttachAction::make()
    ->recordSelectSearchColumns(['resource_name', 'resourceType.resource_type'])

but it doesn't work, it does not make the join in the query.

An other way would be to present a full table of the model to attach to instead of just the select.

Is there a way to setup the attach form to show a full table of resource (with related resource_type column) with filter so that you can select any row to attach to (after eventually filtering)?

Any idea?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Seb
  • 217
  • 1
  • 4
  • 11
  • What is the query it makes? What is the query expected? It would also help if you extracted a [mcve]. – Ulrich Eckhardt Aug 26 '23 at 15:45
  • it queries the related table for the column **resource_name** (it exist) && the column **resourceType.resource_type** (it doesn't exist). What i'd like is that it queries the column **resource_name** from the related table and use the elquent relation **resourceType** to join the table **resource_type** and select the column **resource_type** from it, so that the user is presented with both column and is able to select the relevant **resrouce_name**. I will try to extract a minimal reproducible example soon. – Seb Aug 27 '23 at 09:50
  • You can [edit] your question to add that info. – Ulrich Eckhardt Aug 27 '23 at 21:38
  • To change record title you can add `recordTitle` to your relational table definition. For example `->recordTitle(fn (User $record): string => "{$record->profile->full_name} ({$record->email})")` but this only changes the displayed data, not the searched one – Ratto Aug 29 '23 at 18:16
  • For searching in related fields I haven't found a solution yet, if you find it ping me – Ratto Aug 29 '23 at 18:34

0 Answers0