title: Search function return unwanted results in Laravel
body: <p>I have made search function which looks like is working instead one <code>where</code> clause. I want in the results to not show items which aren't published yet. </p>
  
  <p>So if item has <code>published = 0</code> in database should not be shown on page even if is met the search conditions. </p>
  
  <p>This is my function</p>
  
  <pre><code>public function search(Request $request)
  {
  
      $searchText = strip_tags($request['q']);
      $seachLocation = strip_tags($request['l']);
  
  
      $columns =['alias','description'];
  
      $query = Item::select('*');
  
      $query-&gt;where( 'title', 'like', '%'.$searchText.'%');
      $query-&gt;where('published', 1);
      foreach( $columns as $column) {
          $query-&gt;orWhere( $column, 'like', '%'.$searchText.'%', '%'.$seachLocation.'%');
      }
  
      $query-&gt;orWhereHas('category',function( $query ) use (  $searchText ) {
          $query-&gt;where('title', 'like', '%'.$searchText.'%' );
      });
  
      $query-&gt;orWhereHas('country',function( $query ) use (  $searchText ) {
          $query-&gt;where('name', 'like', '%'.$searchText.'%' );
      });
  
      $items = $query-&gt;paginate(5);
      $searchQuery = $searchText;
      $searchQueryLoc = $seachLocation;
  
  
      return view('search', compact('items','searchQuery','seachLocation'));
  }
  </code></pre>
  
  <p>What I've added is</p>
  
  <pre><code>$query-&gt;where('published', 1);
  </code></pre>
  
  <p>which should carry this condition but I still see unpublished items on page. Why is that?</p>
  
  <p>toSql return</p>
  
  <pre><code>select * from `items` where `title` like ? and `published` = ? and (`alias` like ? or `description` like ?) or exists (select * from `categories` where `items`.`category_id` = `categories`.`id` and `title` like ?) or exists (select * from `countries` where `items`.`country_id` = `countries`.`id` and `name` like ?) limit 5 offset 0
  </code></pre>