Closed ghost closed 6 years ago
You can add custom relationship to your Profile model which will call owner
relationship under the hood with withTrashed()
scope. Like you've done with profile
relation in User model.
Yea, I thought about that but I was wondering if it's really a good idea. Seems kind of a "hacky" solution for me...
Anyway, I probably will opt for this solution.
Thanks for your comment.
I'm closing this issue. If you have more ideas how to solve it - feel free to continue conversation.
Ok thanks! Just to note here, the final solution is:
/**
* Overrides the owner relationship from HasOwner trait adding trashed items.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function owner()
{
return $this->ownedBy()->withTrashed();
}
So, if anyone have similar issues, plz tell me.
My models are:
User implements CanBeOwner contract Profile use HasOwner trait
Both use SoftCascadeTrait
But for Profile model, I don't set this association cause it's already handled by the trait.
The problem is, when fetching Profile content, I need to configure it everytime using ->with().
I just wanna to simplify, call it directly and stay not filtering trashed records. Any thoughts?