Select list: How to handle soft deleted (trashed) relations?

In my form for a QuoteResource I have a Repeater with in there a Selectlist that uses a relation to select a product:
Forms\Components\Select::make( 'product_id' )
->relationship( 'product')
->getOptionLabelFromRecordUsing( fn( Product $record ) => ProductHelper::formatProductToSelectListOptionLabel( $record ) )
->searchable( [ 'name', 'product_number' ] );
Forms\Components\Select::make( 'product_id' )
->relationship( 'product')
->getOptionLabelFromRecordUsing( fn( Product $record ) => ProductHelper::formatProductToSelectListOptionLabel( $record ) )
->searchable( [ 'name', 'product_number' ] );
Now say the product get soft deleted in the meantime. If I go back to editing my quote in which this product was previously selected the selectlist now shows up empty because the product is of course deleted. I expect it to be still filled with the trashed product, but when trying to select a different product it should not show up available for selection. I've tried adding modifyQueryUsing: fn( Builder $query ) => $query->withTrashed() to the relationship parameters but this makes deleted products available for selection when adding a new item as well. Can anybody point me to how to handle this kind of situation?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server