title: Laravel Relationships with a table
body: <p>I am currently struggling as I am quite new to the relationships in Laravel.
  I have a model Products, who is made of one model Material.
  Material can be used in several Products.</p>
  
  <p>I have a table called product_material to link them.</p>
  
  <p>What I have so far 
  In Product</p>
  
  <pre><code>public function material()
  {
      return $this-&gt;hasOne(Material::class, '');
  }
  </code></pre>
  
  <p>In Material</p>
  
  <pre><code> public function products(){
      return $this-&gt;hasMany(Product::class, 'product_material');
  }
  </code></pre>
  
  <p>But this give me an error saying that I dont have any product_id in my material table. </p>
  
  <p>But : My material isnt suppose to have a product_id as when it is created it is not linked to anything and it can be use in several products</p>
  
  <p>Edit: DB structure</p>
  
  <pre><code>Schema::create('products', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
          $table-&gt;string('code',45);
  });
  
  Schema::create('materials', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
          $table-&gt;string('code',45);
  });
  Schema::create('product_material', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
          $table-&gt;integer('product_id');
          $table-&gt;integer('material_id');
      });
  </code></pre>