title: Laravel search through relationship
body: <p>Going straight to the point here.
  I have a search functionality on my List of Items. However, I also want to search all items by category.</p>
  
  <p>Here's what I have done so far.
  I am really new to laravel and eloquent so please bear with me.</p>
  
  <p><strong>Category Table</strong> </p>
  
  <pre><code>public function up()
  {
      Schema::create('categories', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('code', 30);
          $table-&gt;string('name');
          $table-&gt;softDeletes();
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  
  <p><strong>Item Table</strong></p>
  
  <pre><code>public function up()
  {
      Schema::create('items', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;integer('category_id')-&gt;unsigned();
          $table-&gt;string('code', 30);
          $table-&gt;string('name');
          $table-&gt;softDeletes();
          $table-&gt;timestamps();
      });
  
      Schema::table('items', function($table){
          $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('categories');
      });
  }
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>public function search(){
      $q = Input::get ( 'q' );
      if($q != ""){
          $items = Item::with('Category')
                      -&gt;where ( 'name', 'LIKE', '%' . $q . '%' ) 
                      -&gt;orWhere ( 'code', 'LIKE', '%' . $q . '%' )
                      -&gt;whereHas('Category', function($cat){
                          $cat-&gt;where('name', 'hardware');
                      })-&gt;paginate(1)-&gt;setPath('');
  
          $items = $items-&gt;appends ( array (
                      'q' =&gt; Input::get ( 'q' ) 
              ) );
      }else{
          $items = Item::orderBy('id', 'desc')-&gt;paginate(10);
      }
  
      $softDeletesItems = Item::onlyTrashed()-&gt;get();
      return view('item.index', compact('items', 'softDeletesItems'));
  }
  </code></pre>
  
  <p>is there a way for me to do a <code>orWHere('category.name', 'LIKE', '%'. $q .'%')</code>?</p>