laravel - Laravel Livewire 排序国外领域
问题描述
嗨,我有两张表客户和费用我想要的是对第三个字段进行排序,该字段将在客户 foreach 刀片上保持平衡
我的刀片:
<th wire:click="sortBy('total_charges')" >Charge </th>
<th wire:click="sortBy('total_payments')" >Payments</th>
<th wire:click="sortBy('services_count')">balance</th>
<td>{{ $customer->total_charges}}€ </td>
<td>{{ $customer->total_payments}}€</td>
<td>{{ $customer->total_payments - $customer->total_charges}}€</td>
当然,我在 foreach 中拥有与客户表相关的其他数据
我的qyery:
public function render()
{
$customers = Customer::query()
->search($this->search)
//->selectRaw('*, total_charges - total_payments as balance',)
->withSum('charges as total_charges','taskscharges')
->withSum('charges as total_payments','payment')
->withCount('charges')
->orderBy($this->sortBy,$this->sortDirection)
->paginate($this->perPage);
return view('livewire.customers.show',['customers'=>$customers
])
->extends('layouts.maindashboard')
->section('content');
}
如您所见,我注释掉了->selectRaw('*, total_charges - total_payments as balance',)
因为字段> total_charges 和total_payments 是外部表的总和的错误,所以有什么简单的方法可以识别为余额来进行排序吗?
解决方案
推荐阅读
- python - python3中的消息缓冲区表示
- javascript - 合并数组中的重复对象并添加其他属性
- java - 我可以在文件(Android)中传递空值吗
- javascript - 如何使 globalCompositeOperationSection 仅影响 save() 和 restore() 上下文?
- google-play-console - 允许第一次发布的版本代码 2?
- firebase - firebase 的 Blaze 计划中的同时连接
- javascript - Jquery 函数返回数据完全被忽略
- python - 为什么 BeautifulSoup4 中标签的兄弟姐妹可以是字符串?
- android - 尝试获取特定节点上可用但无法从 firebase 数据库中获取数据的数据
- python - 如何循环 python 命令一定次数?