title: getting all the data from pivot table in laravel
body: <p>i'm trying to get all the lead_id inside my pivot table but i can't make it work.</p>
  
  <p><strong>controller:</strong></p>
  
  <pre><code>     $levels = Level::all();
       $levels-&gt;lead()-&gt;attach('lead_id');
       return $levels;
  </code></pre>
  
  <p><strong>Model Level:</strong></p>
  
  <pre><code>public function lead(){
      return $this-&gt;belongsToMany(Lead::class, 'level_students')-&gt;withPivot('level_id', 'lead_id');
    }
  </code></pre>
  
  <p><strong>Model Lead:</strong></p>
  
  <pre><code> public function level(){
  return $this-&gt;belongsToMany(Level::class, 'level_students')-&gt;withPivot( 'lead_id', 'level_id');
  </code></pre>
  
  <p>}</p>