Hi Folks,
I have several models that contain a polymorphic field. These poly fields contain four or five relationships each, some are soft deleteable, some are not. I'm running into a 'damned if you do, damned if you don't' problem and not sure how to solve.
If I load with a call to eager loading without including trashed on the models that have softdeletes:
$deptRisks = \App\DeptRisk::with(['owner', 'riskable']);
I will get the following error on those models that have been soft-deleted: Trying to get property of non-object
If I load WITH the withTrashed for the softdeletes:
$deptRisks = \App\DeptRisk::with(['owner', 'riskable' => function ($query) {
$query->withTrashed();
}]);
I will get the following error on those models that have NOT been set up as soft-deletes: Call to undefined method Illuminate\Database\Query\Builder::withTrashed()
I'm sure I'm missing something obvious, but I'm spinning in circles. Please help.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community