title: One-To-Many Relation with Pivot Table
body: <p>I have 2 tables Manufacturers and Suppliers ,and they have Many-to-Many relation </p>
  
  <pre><code>Schema::create('manufacturers', function (Blueprint $table) {
         $table-&gt;increments('id');
         $table-&gt;string('name')-&gt;unique();
         $table-&gt;timestamps();
  }); 
  
    Schema::create('suppliers', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;string('location');
          $table-&gt;timestamps();
   ​ });
  </code></pre>
  
  <p>so i created a pivot table called "manufacturer_supplier" and it works fine.</p>
  
  <pre><code>Schema::create('manufacturer_supplier', function (Blueprint $table) {
  
  $table-&gt;increments('id');
  $table-&gt;integer('manufacturer_id')-&gt;unsigned()-&gt;index();
  $table-&gt;integer('supplier_id')-&gt;unsigned()-&gt;index();
  $table-&gt;timestamps();
  
  $table-&gt;foreign('manufacturer_id')-&gt;references('id')-&gt;on('manufacturers')-&gt;onDelete('cascade');
  $table-&gt;foreign('supplier_id')-&gt;references('id')-&gt;on('suppliers')-&gt;onDelete('cascade');
   });
  </code></pre>
  
  <p>My confusion comes from adding a new table "devices"</p>
  
  <pre><code>Schema::create('devices', function (Blueprint $table) {
  
  $table-&gt;increments('id');
  $table-&gt;string('serial')-&gt;unique();
  $table-&gt;string('name');
  ​$table-&gt;integer('supplier_id')-&gt;unsigned()-&gt;nullable();
  $table-&gt;integer('manufacturer_id')-&gt;unsigned()-&gt;nullable();
  $table-&gt;text('notes')-&gt;nullable();
  $table-&gt;timestamps();
  
  $table-&gt;foreign('supplier_id')-&gt;references('id')-&gt;on('suppliers')-&gt;onDelete('cascade');
  $table-&gt;foreign('manufacturer_id')-&gt;references('id')-&gt;on('manufacturers')-&gt;onDelete('cascade');
   });
  </code></pre>
  
  <p>where i want to have a one-to-many relation with each of suppliers and manufacturers , so i would have a select list of manufacturers and then populate the next list from with suppliers from Pivot table that relate to the selected manufacturer.</p>
  
  <p>currently my  "device"​ model has the following relations which it relate them to the original table not the pivot so it doesn't work </p>
  
  <pre><code>//5
  public function manufacturer(){
  
  return $this-&gt;belongsTo('App\Manufacturer');
  }
  //6
  
  public function supplier(){
  
  return $this-&gt;belongsTo('App\Supplier');
  }
  </code></pre>
  
  <p>I haven't done that before so i'm curious to know what will be the best fix for this to work.
  Thanks a lot ,</p>