Yes it worked! that exactly i want , to recognize the balance as balance property,
I make Sum('balance') and finally i get the total balance,
one last think , i inserted that to the previous function is it possible to have to returns or whaterver is it and call it on blade like > taks->total_tasks and tasks->total_balance?
as you can see i commented the first return ,
Now i have on render :
return view('livewire.customers.show',['customers' => $customers],['tasks' => $this->tasks()])
and on blade call the $tasks, how can i define the first return or the second return to show?
above the function :
public function tasks()
{
//return charge::where('success', 0)->count();
$chargesSubQuery = Charge::selectRaw('customer_id, SUM(taskscharges - payment) as balance')
->groupBy('customer_id');
return Customer::query()
->select('customers.*', 'balances.balance')
->joinSub($chargesSubQuery, 'balances', fn ($join) => $join->on('customers.id', '=', 'balances.customer_id'))
->sum('balance');
}