5

私はlaravelの初心者で、検索クエリを作成しました。検索するタグもありますが、検索方法がわかりません

クエリは次のようになります

public function post_search()
    {
        $tags = Input::get('tag_id');

        $search =  $this->user
                        ->with('tag')
                        ->where('username', 'LIKE', '%'.Input::get('username').'%')
                        ->where('first_name', 'LIKE', '%'.Input::get('first_name').'%')
                        ->where('last_name', 'LIKE', '%'.Input::get('last_name').'%')
                        ->where('group_id', 'LIKE', '%'.Input::get('group_id').'%')
                        ->where('tag_id', 'LIKE', '%'.$tags.'%')
                        ->paginate(22);

        $this->layout->title   = "Search results";
        $this->layout->content = View::make("home.results")
                               ->with('users', $search);

    }

そして、tag_id 入力は次を返します

array(5) {
  [0]=>
  string(2) "20"
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "3"
  [3]=>
  string(1) "2"
  [4]=>
  string(2) "15"
}

検索でタグを実装する方法を教えてください。

ありがとうございました

編集

タグでこのエラーが発生しています

Array to string conversion
4

1 に答える 1

4

あなたのクエリでは

->where('tag_id', 'LIKE', '%'.$tags.'%')

and$tagsは配列ですが、一緒に使用したlikeため、 Array to string conversionエラーが発生しました。使用する必要があります

->whereIn( 'tag_id', $tags );

ララベルのドキュメント。

于 2013-05-27T16:28:19.403 に答える