title: How to use laravel relations to get data from database
body: <p>I am wokring on a home page in which I have to show the Feature Category Supplier slider.
  Hear is what I want:</p>
  
  <p>I want to get the random 3 Featured categories form category table and of that each category have 6 suppliers which i also want to display.</p>
  
  <p>Database Structure:</p>
  
  <h3>Category Table contain the <code>is_featured</code> Flag.</h3>
  
  <pre><code>id  | is_featured
  
  1   |   1
  2   |   1
  3   |   1
  4   |   1
  ... so on
  </code></pre>
  
  <p>I have supplier categories table in which i have mapped the supplier and there categories.</p>
  
  <h3>SupplierCategoryMappingTable</h3>
  
  <pre><code>id  | sup_id | cat_id
  1   |   1    |  1
  2   |   2    |  2
  3   |   3    |  3
  4   |   4    |  4
  5   |   5    |  5
  ...so on
  </code></pre>
  
  <p>And Supplier table in which i have supplier details.</p>
  
  <h3>Supplier Table</h3>
  
  <pre><code>id  | sup_name ....Other details
  1   | ABC
  2   | DEF
  3   | HIJ
  4   | LLK
  5   | OPQ
  6   | SDE
  ...so on 
  </code></pre>
  
  <h2>What i have tried so far.</h2>
  
  <p>I have trid to give <code>hasMany</code> Relation but get empty item array.I am thinking that category has many supplier so i have added has many.</p>
  
  <pre><code>public function supplierList() 
  {
      return $this-&gt;hasMany('App\DB\Supplier\SupplierCategoryDetail', 'cat_id', 'id');        
  }
  </code></pre>
  
  <p>Some how i have figur it out to get random category. but after using <code>with()</code> it gives empty result.</p>
  
  <pre><code>$data['featured_category'] = Category::with('supplierList')-&gt;where('status','1')-&gt;inRandomOrder()-&gt;limit(3)-&gt;get();`
  </code></pre>
  
  <p>I am completely new in laravel and it's relations. I am doing this using eloquent in laravel. </p>