title: Laravel search 'LIKE' query in two tables
body: <p>I'm currently trying to set up a search bar that filters the results of two tables, <strong>books</strong> and <strong>categories</strong>.</p>
  
  <p>I have setup relationships for both models where:</p>
  
  <p>Book.php (Model) <strong>(table: id, b_name, b_author, cat_id)</strong></p>
  
  <pre><code>public function bookCategory()
  {
    return $this-&gt;belongsTo('Category', 'cat_id', 'id');
  }
  </code></pre>
  
  <p>Category.php (Model) <strong>(table: id, cat_name)</strong></p>
  
  <pre><code>public function book()
  {
    return $this-&gt;hasMany('Book', 'cat_id', 'id');
  }
  </code></pre>
  
  <p>BookController.php</p>
  
  <pre><code>public function getFilterBooks($input)
  {
    $books = Book::with('bookCategory')-&gt;where('**cat_name at category table**. 'LIKE', '%' . $input . '%'')-&gt;get();
  
    return Response::json($books);
  }
  </code></pre>
  
  <p>But obviously this won't work. The reason I'm doing this is because I want to allow users to use the same search bar to filter different columns (which I know how to do it in one table, but not two or more).</p>