【发布时间】:2021-10-30 05:55:38
【问题描述】:
我使用 Livewire 并为表格放置一个过滤器。 我的组件有以下代码:
use WithPagination;
public bool $loadData = false;
public $filter_type = null;
protected $queryString = ['filter_type'];
public function setType($type)
{
$this->filter_status = $type;
}
public function render()
{
$transactions = Transaction::when($this->filter_type, function ($query){
$query->where('type' , $this->filter_type);
})
->orderBy('created_at', 'DESC')
->get();
return view('livewire.backend.financial.transactions')->with('transactions' , collect($transactions)->paginate(10));
}
当我应用过滤器时。网址如下
https://example.com/table?filter_type=0
现在我想给filter_type两个值(例如0和1)
也就是说,显示类型为 0 和 1 的项目。
我该怎么做?
【问题讨论】:
-
我认为您还有另一个问题:您在 setType 函数中设置的字段与您在查询字符串中使用的字段不同。