title: how to save many data in pivot table in laravel
body: <p>i want to save two data (qte and total) in pivot table, how can i do that</p>
  <hr />
  <p>here my code</p>
  <hr />
  <p>artical model</p>
  <pre><code>class Artical extends Model{
  
  protected $table = 'artical';
  protected $primaryKey = 'ida';
  protected $fillable = [ 'num_art' , 'designation', 'unite','prix_unit',];}
  </code></pre>
  <hr />
  <p>devis model</p>
  <pre><code>class Devis extends Model{
  
  protected $table = 'Devis';
  protected $primaryKey = 'idd';
  protected $fillable = ['type', 'lot', 'prix_total_avant_tax', 'tax_perse', 'tax_amount', 'prix_total_apre_tax', 'notes',];
  
  
  public function articals()
  {
      return $this-&gt;belongsToMany(Artical::class)-&gt;withPivot(['qte'])-&gt;withPivot(['total']);
  }}
  </code></pre>
  <hr />
  <p>devis_artical table (pivot tavle)</p>
  <p><a href="https://i.stack.imgur.com/7Nfgj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7Nfgj.png" alt="enter image description here" /></a></p>
  <hr />
  <p>store function</p>
  <pre><code>public function store(Request $request)
  {
  
      $Devis = Devis::create($request-&gt;all());
  
  
      $articals = $request-&gt;input('articals', []);
      $quantité = $request-&gt;input('quantité', []);
      $total = $request-&gt;input('total', []);
  
      for ($product=0; $product &lt; count($articals); $product++) {
      if ($articals[$product] != '') {
          $Devis-&gt;articals()-&gt;attach($articals[$product], ['qte'=&gt; $quantité[$product]], ['total'=&gt; $total[$product]]);
      }
  }
  
      return redirect('/Devis');
  }
  </code></pre>