F
Filament16mo ago
darwin

Displaying related data on form fields from deleted record.

Hello everyone, i just want to ask how do i display the data from related models on the form fields when a record is soft deleted. i just noticed that the data from other models doesnt exist anymore on the fields and i need to restore the record in order to display it again. thanks!
3 Replies
Patrick Boivin
Patrick Boivin16mo ago
Hi @Jr. BE dev, can you share a bit of your form code? Just to show how you are using the relationship.
cheesegrits
cheesegrits16mo ago
One way would be to to remove the soft deleting scope from the relationship itself, although that would probably have undesirable side effects ...
public function thing(): YourRelationshipType
{
return $this->yourRelationshipType(Thing::class)->withoutGlobalScope(SoftDeletingScope::class);
}
public function thing(): YourRelationshipType
{
return $this->yourRelationshipType(Thing::class)->withoutGlobalScope(SoftDeletingScope::class);
}
You might also try removing it from the modifyQueryUsing closure on the relationship() within Filament, like if using a group with a relationship ...
Forms\Group::make()
->relationship(
'things',
fn (Builder $query) => $query->withoutGlobalScope(SoftDeletingScope::class)
)
Forms\Group::make()
->relationship(
'things',
fn (Builder $query) => $query->withoutGlobalScope(SoftDeletingScope::class)
)
But really ... you might reconsider your use of soft deletes, if you are allowing soft deletion of data which is still required elsewhere. Implement your own 'status' mechanism, which allows setting a record to inactive, and use that to show/hide the record. When you find yourself fighting built in mechanisms like this, you're usually using the wrong approach.
darwin
darwinOP16mo ago
good day, i finally fixed this issue the other day by the way. Yes you are correct i was not using the relationship of the models correctly to show related data. thank you!
Want results from more Discord servers?
Add your server