使用输入数组的Laravel搜索查询

Web*_*ent 5 php search laravel

我是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);

    }
Run Code Online (Sandbox Code Playgroud)

并且tag_id输入返回以下内容

array(5) {
  [0]=>
  string(2) "20"
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "3"
  [3]=>
  string(1) "2"
  [4]=>
  string(2) "15"
}
Run Code Online (Sandbox Code Playgroud)

可以请有人给我一个暗示我如何在我的搜索中实现标签?

谢谢

编辑

我用标签得到这个错误

Array to string conversion
Run Code Online (Sandbox Code Playgroud)

The*_*pha 4

在你的查询中你有

->where('tag_id', 'LIKE', '%'.$tags.'%')
Run Code Online (Sandbox Code Playgroud)

and$tags是一个数组,但你使用了它,like所以你得到了 Array to string conversion错误。你应该使用

->whereIn( 'tag_id', $tags );
Run Code Online (Sandbox Code Playgroud)

Laravel 文档。