title: Adding unique value in pivot table
body: <p>I have many to many relationship of level and subjects.To add subjects in the subject table and levels in the level table i have a code below:</p>
  
  <pre><code>public function store(Request $request,Level $level)
  {
      DB::transaction(function () use ($request, $level) {
          foreach ($request-&gt;get('subject') as $value) {
              $subject = Subject::find($value);
              if(is_null($subject)){
                  $s = Subject::create(['name'=&gt;$value]);
                  $level-&gt;subjects()-&gt;attach($s-&gt;id);
              }
              else{
                  $level-&gt;subjects()-&gt;attach($value);
              }
          }
      });
  }
  </code></pre>
  
  <p>My problem is that i want to add the unique subject for a level in the pivot table.
  Is there any solution i could unique subject for a particular level in pivot table?</p>