我正在尝试创建一个多重选择过滤器。当我使用where作为id时,我得到了这个错误
无效的参数号(SQL: select * from
stations
whereid
in (16128))
16128是为该查询选择的两个id之一。它工作得很好,一个手动给定的数组,所以我不确定问题是什么。我也尝试了array_values,但我得到了相同的结果。
<label for="" class="col-md-3">Daypart</label>
<div class="container-checkbox">
@foreach($dayparts as $id => $daypart)
<div wire:key="{{ $daypart->id }}">
<input type="checkbox" id="{{ $daypart->daypart_name }}" name="{{ $daypart->daypart_name }}" wire:model="filters.dayparts.{{ $daypart->id }}" wire:click="filtru({{ $daypart->id }})" />
</div>
@endforeach
</div>
public function filtru($id){
$this->filters['dayparts'] = array_filter($this->filters['dayparts']);
$dayp = DaypartStation::whereIn('daypart_id', array_keys($this->filters['dayparts']))->get();
foreach($dayp as $day){
$this->arr[]=$day->station_id;
}
$toate = Station::whereIn('id', [$this->arr])->get();
//dd(Station::whereIn('id', $this->arr)->get());
//dd(Station::whereIn('id', [array_values($this->arr)])->get());
// dd(Station::whereIn('id', [16576, 16776, 16376])->get());
}
public function render()
{
return view('livewire.create-workbooks-table', [
'stations'=> Station::
when($this->filters['dayparts'], function($query){
$query->whereIn('id', [$this->arr]);
})
->search($this->search)
->orderBy($this->sortBy, $this->sortDirection)
->latest()
->Paginate($this->perPage),
]);
}
我认为你应该改变
$toate = Station::whereIn('id', [$this->arr])->get();
$toate = Station::whereIn('id', $this->arr)->get();
因为$this->arr
已经是一个数组