亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

array_merge(): 參數 #2 不是 sidefilter 上的數組

array_merge(): 參數 #2 不是 sidefilter 上的數組

PHP
烙印99 2023-04-21 14:06:58
我在一個問題上遇到了麻煩。在側邊欄過濾器功能中,當我單擊復選框時,它將正確顯示列表。但是當我取消選中復選框時,它將顯示“array_merge(): Argument #2 is not an array”檢查元素時顯示此錯誤。當我點擊復選框時,它會生成這個 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'));        });
查看完整描述

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'));

    }


查看完整回答
反對 回復 2023-04-21
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號