I am looking for the Eloquent, or raw sql, to get the sums of two of my ->withCount. I need to be able to do this without having to ->get() the records, it needs to be implemented using Eloquent, not laravels Collection methods.
I have the following:
$owners = User::active() ->where(function($q){ $q->whereHas('primaryContractOwner') ->orWhereHas('primaryVendorOwner'); }) ->withCount([ 'primaryContractOwner', 'primaryVendorOwner' ]); I need to get the sum of primary_contract_owner count and primary_vendor_owner count. I tried the following but I am getting primary_contract_owner_count column not found
// This one throws the error $owners = User::active() ->where(function($q){ $q->whereHas('primaryContractOwner') ->orWhereHas('primaryVendorOwner'); }) ->withCount([ 'primaryContractOwner', 'primaryVendorOwner' ]) ->select(['user.*', DB::raw('primary_contract_owner_count + primary_vendor_owner')]);