I am a begginer with laravel and i made a search query, and i have tags to search for too, but i dont know how to search for it
Query looks like this
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);
}
And the tag_id input returns the following
array(5) {
[0]=>
string(2) "20"
[1]=>
string(1) "1"
[2]=>
string(1) "3"
[3]=>
string(1) "2"
[4]=>
string(2) "15"
}
Could please someone give me a hint how i can implement the tags in my search?
Thank you
EDIT
I am getting this error with tags
Array to string conversion
In your query you have
->where('tag_id', 'LIKE', '%'.$tags.'%')
and $tags
is an array but you used it with like
so you got Array to string conversion
error. You should use
->whereIn( 'tag_id', $tags );
Laravel Documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With