Filament Multi-Select Not Loading Default Values from Third Table (Not Pivot Table)
Hi all,
I'm facing an issue with Filament in Laravel where a multi-select field isn't loading its default values in the edit form. My setup involves saving selected values in a third table, which isn't a traditional pivot table but rather an additional table (CarUsageRecord) related to a Task model.
The Problem
When editing a record, the default function in Select::make doesn't run, so the previously selected values from the third table aren't loaded into the select field, making it impossible to see what was selected before.
My Setup
Task model: Has a one-to-many relationship with CarUsageRecord.
CarUsageRecord model: Stores car_id and task_id to track which cars are linked to a task.
Task model relationship:
Form setup in the Filament resource:
What I've Tried
Attempted to use the default method to load selected car IDs, but it doesn’t run during form load.
Used dump() and Log::info() for debugging inside the default method, but no output indicates the method is not executing.
Saving works fine, but loading the values during edit is the issue.
What I Need
How can I ensure the default method runs during form load?
What’s the best way to load values into a multi-select field from a third table?
Any advice would be appreciated!
2 Replies
As far as I understand (I didn't check),
If you are modifying the way it is saved, you should also modify the way you retrieve it. For that, you have:
getSearchResultsUsing()
Thanks for the idea. This is how it was solved: