Access nested sum
How can I display the
dose_count
inside a TextColumn?
Solution:Jump to solution
I am not sure, because I solved this - but I think this way I would loose sorting, or would have to implement it manually.
I fixed it by defining the needed relationship inside the model, so I don't have to traverse.
https://github.com/staudenmeir/eloquent-has-many-deep...
GitHub
GitHub - staudenmeir/eloquent-has-many-deep: Laravel Eloquent HasMa...
Laravel Eloquent HasManyThrough relationships with unlimited levels - GitHub - staudenmeir/eloquent-has-many-deep: Laravel Eloquent HasManyThrough relationships with unlimited levels
6 Replies
Doesn't
TextColumn::make('patients.dose_count')
work?@Dennis Koch unfortunately not. Maybe some information are missing from my side.
Hospital
->hasMany -> Doctor
-> hasMany -> Patient
-> hasMany PatientProtocol
I want from the HospitalResource to sum all doses.If it's the HospitalResource, then you are missing the link to doctors? Not sure if that works with Eloquent. Maybe you need to write your own subselect.
The Hospital has a relation to Patients through Doctors (HasManyThrough). So I actually can sum other columns that are in the patient table already. But going one more deep is kind of not working.
I think the issue is, that you have an array of patients then. So you'd need to sum those too:
Solution
I am not sure, because I solved this - but I think this way I would loose sorting, or would have to implement it manually.
I fixed it by defining the needed relationship inside the model, so I don't have to traverse.
https://github.com/staudenmeir/eloquent-has-many-deep
GitHub
GitHub - staudenmeir/eloquent-has-many-deep: Laravel Eloquent HasMa...
Laravel Eloquent HasManyThrough relationships with unlimited levels - GitHub - staudenmeir/eloquent-has-many-deep: Laravel Eloquent HasManyThrough relationships with unlimited levels