title: Laravel 5.4 - get entrys where column contains specific string
body: <p>I'm geting the following error if I try to get database entrys where the name contains a passed string. </p>
  
  <pre><code>Invalid argument supplied for foreach()
  </code></pre>
  
  <p>.</p>
  
  <pre><code>$search = $request['search'];
  $key_search = explode(' ', $search);
  $usergroups = Usergroups::whereIn('name', 'like', '%' . $search . '%')-&gt;paginate(3);
  </code></pre>
  
  <p>$key_search looks something like this: <code>[0 =&gt; "Test", 1 =&gt; "Unicorn"];</code></p>
  
  <p>Now I want to get every entry where the name column has data that contains the passed strings and get the query results with <code>paginate();</code> </p>
  
  <p>I've also tried something like a foreach loop that pushes the entrys into another array but this haven't worked for me as well cause the entrys are Objects and not arrays. Thats why array_push coulnd't handle this.</p>
  
  <p>Does someone know what I can do to get the entrys? </p>
  
  <p>Thanks for your help and sorry for my bad english!</p>
  
  <hr>
  
  <p>Based on answer: </p>
  
  <p>Problem is that I get every entry in my database. At first the entrys that matches with the search keys and the last entrys doesn't match with the search keys at all.</p>
  
  <p>example: </p>
  
  <p>I'm passing "test" and "unicorn" </p>
  
  <p>And I have 10 entrys in my database. For example: </p>
  
  <ol>
  <li>test dkkawdmawkdkaw </li>
  <li>mdkawdawtestdmwakdaw // test</li>
  <li>apples</li>
  <li>oranges</li>
  <li>anything</li>
  <li>Unicorn  /// Unicorn - U is uppercase</li>
  <li>more unicornsdawdawd //unicorn</li>
  <li>pizza</li>
  <li>testing</li>
  <li>i'm not creative</li>
  </ol>
  
  <p>So I only want: 1,2,6,7 and 9. But I'm getting all of them sorted from high matches to doesn't match at all. </p>