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 關注
- 124 瀏覽
添加回答
舉報