1 回答
TA贡献1877条经验 获得超1个赞
我认为你的控制器有问题:你有 whereIn 查询需要在第二个参数上传递数组。但是你的 id 是空的,为什么它会给出这样的错误。尝试将代码更改为以下将起作用。
public function genresFilter ()
{
$sortBy = Input::get('sortBy', 'id');
$dir = Input::get('direction', 'desc');
$orderBy = [
'tracks'=>[ 'order_by'=>$sortBy, 'direction'=>$dir ]
];
$id = Input::get('id');
// check if id is not array, then give empty array
if(!is_array($id)) $id = [];
$category = Category::where('slug','music-genre')->first();
$tag = Tag::with('tracks','elements')->where('category_id', $category->id)->whereIn('id', $id)->get();
echo "<pre>";
print_r($tag->toArray());
die();
$this->layout->content = View::make('public.tags.genres', compact('tag'));
}
解决方案 2
public function genresFilter ()
{
$sortBy = Input::get('sortBy', 'id');
$dir = Input::get('direction', 'desc');
$orderBy = [
'tracks'=>[ 'order_by'=>$sortBy, 'direction'=>$dir ]
];
$id = Input::get('id');
$category = Category::where('slug','music-genre')->first();
$tag = Tag::with('tracks','elements')->where('category_id', $category->id);
// if id is not null and and array then we do filter
if($id != null && is_array($id)) {
$tag->whereIn('id', $id);
}
$tag->get();
echo "<pre>";
print_r($tag->toArray());
die();
$this->layout->content = View::make('public.tags.genres', compact('tag'));
}
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报