Php array_merge():参数#2不是sidefilter上的数组
Php array_merge():参数#2不是sidefilter上的数组,php,jquery,laravel,Php,Jquery,Laravel,我在一个问题上遇到了麻烦。在边栏过滤器功能中,当我单击复选框时,它将正确显示列表。但当我取消选中复选框时,它将显示“array_merge():Argument#2不是数组”,在检查元素时显示此错误。 当我单击复选框时,它将生成此url“http://abc.local/genre-tags/?id%5B%5D=31" . 当我取消选中复选框时,它将显示url“http://abc.local/genre-tags/“错了。 下面是控制器和js代码 public function genres
我在一个问题上遇到了麻烦。在边栏过滤器功能中,当我单击复选框时,它将正确显示列表。但当我取消选中复选框时,它将显示“array_merge():Argument#2不是数组”,在检查元素时显示此错误。 当我单击复选框时,它将生成此url“http://abc.local/genre-tags/?id%5B%5D=31" . 当我取消选中复选框时,它将显示url“http://abc.local/genre-tags/“错了。 下面是控制器和js代码
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)->whereIn('id', $id)->get();
echo "<pre>";
print_r($tag->toArray());
die();
$this->layout->content = View::make('public.tags.genres', compact('tag'));
}
//Sidebar Filter Genre Tracks
$(document).ready(function () {
$('.genreTag').on('change', function (e)
{
$('input.filter-playlist, .popularGenreTag, .mood-emotion, .production-type, .vocals, .all-tracks, .last-year, .last-month, .last-week, .last-day').each(function() {
var $this = $(this);
$this.prop('checked', false);
$this.parent().find('> div').removeClass('chk-checked').addClass('chk-unchecked');
});
e.preventDefault();
id = [];
$('.genreTag:checked').each(function()
{
id.push($(this).attr('id'));
});
$.get("/genre-tags/", {id: id}, function(data)
{
hideLoader();
refreshedPage = $(data);
newDemo = refreshedPage.find(".libraryWrapper, .albumWrapper, .composersWrapper, .albumsListWrapper, .albumsWrapper, .accountWrapper, .distributionsWrapper, .PaymentsWrapper, .contactWrapper, .contractsWrapper, .toolsWrapper, .blogWrapper, .pageWrapper, .cartWrapper, .pageWrapper").html();
$('.libraryWrapper, .albumsWrapper, .albumWrapper, .composersWrapper, .albumsListWrapper, .accountWrapper, .distributionsWrapper, .PaymentsWrapper, .contactWrapper, .contractsWrapper, .toolsWrapper, .blogWrapper, .pageWrapper, .cartWrapper, .pageWrapper').html(newDemo);
activatePlayer()
initTrackInfo();
});
});
});
公共函数genresFilter()
{
$sortBy=Input::get('sortBy','id');
$dir=Input::get('direction','desc');
$orderBy=[
'曲目'=>['按'=>$sortBy'排序,'方向'=>$dir]
];
$id=Input::get('id');
$category=category::where('slug','music-genre')->first();
$tag=tag::with('tracks','elements')->where('category_id',$category->id)->where('id',$id)->get();
回声“;
打印($tag->toArray());
模具();
$this->layout->content=View::make('public.tags.genres',compact('tag');
}
//边栏过滤器类型曲目
$(文档).ready(函数(){
$('.genreTag')。关于('change',函数(e)
{
$('input.filter-playlist、.popularGenreTag、.mood-emotion、.production-type、.vocals、.all-track、.last-year、.last-month、.last-week、.last-day')。每个(函数(){
var$this=$(this);
$this.prop('checked',false);
$this.parent().find('>div').removeClass('chk-checked').addClass('chk-unchecked');
});
e、 预防默认值();
id=[];
$('.genreTag:checked')。每个(函数()
{
id.push($(this.attr('id'));
});
$.get(“/genre tags/”,{id:id},函数(数据)
{
hideLoader();
刷新页面=$(数据);
newDemo=refreshedPage.find(“.libraryWrapper、.albumWrapper、.CompositeSWrapper、.albumsListWrapper、.albumsWrapper、.accountWrapper、.distributionsWrapper、.PaymentsWrapper、.contactWrapper、.contractsWrapper、.blogWrapper、.pageWrapper、.CartWrappe;
$('.libraryWrapper、.albumWrapper、.albumWrapper、.ComposeWrapper、.albumsListWrapper、.accountWrapper、.DistributionWrapper、.PaymentWrapper、.contactWrapper、.ContractWrapper、.toolsWrapper、.blogWrapper、.pageWrapper、.cartWrapper;
activatePlayer()
initTrackInfo();
});
});
});
Route::get('genre-tags/,['as'=>'标记。popular-genres','uses'=>'SideFilterController@genresFilter']);
//复选框刀片文件
{{{$genreTag->name}}}({{count(json_decode($genreTag->elements,true))+count(json_decode($genreTag->tracks,true))})
我认为您的控制器存在问题:
您有一个需要在第二个参数上传递数组的查询。但是你的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');
$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'));
}
公共函数genresFilter()
{
$sortBy=Input::get('sortBy','id');
$dir=Input::get('direction','desc');
$orderBy=[
'曲目'=>['按'=>$sortBy'排序,'方向'=>$dir]
];
$id=Input::get('id');
//检查id是否不是数组,然后给出空数组
如果(!is_数组($id))$id=[];
$category=category::where('slug','music-genre')->first();
$tag=tag::with('tracks','elements')->where('category_id',$category->id)->where('id',$id)->get();
回声“;
打印($tag->toArray());
模具();
$this->layout->content=View::make('public.tags.genres',compact('tag');
}
解决方案2
公共函数genresFilter()
{
$sortBy=Input::get('sortBy','id');
$dir=Input::get('direction','desc');
$orderBy=[
'曲目'=>['按'=>$sortBy'排序,'方向'=>$dir]
];
$id=Input::get('id');
$category=category::where('slug','music-genre')->first();
$tag=tag::with('tracks','elements')->其中('category_id',$category->id);
//若id不为null且为and array,则我们进行筛选
如果($id!=null&&is_数组($id)){
$tag->其中('id',$id);
}
$tag->get();
回声“;
打印($tag->toArray());
模具();
$this->layout->content=View::make('public.tags.genres',compact('tag');
}
@iAmGroot great it helphi@sok hai。。。。在live上给我这个错误“SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;请检查与您的MySQL服务器版本相对应的手册第1行(SQL:select*fromtags
wherecategory\u id
=1和id
in())”键入:“Illumb\Database\QueryException”“您能帮助我吗。@iAmGroot如果不能。我更新了解决方案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');
// 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'));
}
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'));
}