Select with multiple doesn't show previously selected record because they are softdeleted

I know it is because of Laravel eloquent and i could change the query to withTrashed but the hard part is that the options should not list softdeleted, because in the app they are "archived", but the previously selected options should. I can make the "same" option work in relations that store a id on the table using getOptionLabelUsing, i tried using getOptionLabelsUsing on the multiple form Select but to no affect, any on how to make it work?
5 Replies
toeknee
toeknee2mo ago
Just modify the query, to search as normal but with a orWhere('id', '=', $state) i.e.
Select::make('author_id')
->relationship(
name: 'author',
modifyQueryUsing: fn (Builder $query, $state) => $query->orWhere('id', '=', $state),
)
Select::make('author_id')
->relationship(
name: 'author',
modifyQueryUsing: fn (Builder $query, $state) => $query->orWhere('id', '=', $state),
)
Firebat
FirebatOP2mo ago
the thing is that i keep getting null on the $state variable, maybe be cause the $state is set after que query is finished? Maybe because the state is not stored in the table in the db like the non pivot relations i was thinking about trying to use livewire to check if it is a instance of edit, then modify the query to force the load the relations listed in the pivot
toeknee
toeknee2mo ago
Maybe see if $record can be used? else try $livewire and also make the select a live()
Firebat
FirebatOP2mo ago
well, $record exists and points to the current record on edit and on create returns null as expected.
Firebat
FirebatOP2mo ago
if anyone falls on this thread, here's a example of a bad query you could do to solve the problem
No description
Want results from more Discord servers?
Add your server