title: Multi-select dropdown with Many to many relation
body: <p>In my laravel project I created three tables as <strong>employees</strong>, <strong>teams</strong> and <strong>employee_teams</strong>. There is  many to many relationship in "employee_teams" tables, with the foreign keys of <code>employee_id</code> and <code>team_id</code>.</p>
  
  <p>"employee_teams" table DB structure</p>
  
  <p>id | employee_id | team_id</p>
  
  <p>In the Employee form there is a multi-select dropdown which helps to assign multiple teams for the particular employee.</p>
  
  <pre><code>&lt;select name="namedropdown[]" id="namedropdown" class="selectpicker" multiple data-live-search="true"&gt;
      &lt;option value="" disabled selected&gt;Nothing selected&lt;/option&gt;
           @foreach ($tdropdown as $key =&gt; $tdrop)
           &lt;option value="{{$key}}"&gt;{{$tdrop}}&lt;/option&gt;
           @endforeach
  &lt;/select&gt;
  </code></pre>
  
  <p>What I want is to <strong>save "team_id" and "employee_id", to the "employee_teams" table</strong>.</p>
  
  <p>Here is employee model</p>
  
  <pre><code>class employee extends Model
  {  
      public function teams()
      {
           return $this-&gt;belongsToMany(team::class, 'employee_teams');
      }
  }
  </code></pre>
  
  <p>Here is team model</p>
  
  <pre><code>class team extends Model
  {
      public function employees()
      {
           return $this-&gt;belongsToMany(employee::class, 'employee_teams');
      }
  }
  </code></pre>
  
  <p>Here is employee_team table migration</p>
  
  <pre><code>class CreateEmployeeTeamsTable extends Migration
  {
      public function up()
      {
          Schema::create('employee_teams', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;integer('employee_id')-&gt;unsigned();
              $table-&gt;integer('team_id')-&gt;unsigned();
              $table-&gt;foreign('employee_id')-&gt;references('id')-&gt;on('employees')-&gt;onDelete('cascade');
              $table-&gt;foreign('team_id')-&gt;references('id')-&gt;on('teams')-&gt;onDelete('cascade');
              $table-&gt;timestamps();
          });
      }
  </code></pre>
  
  <p>Here is store function in employee controller</p>
  
  <pre><code>use App\employee;
  use App\team;
  use App\employee_team;
  
  // codes
  
   $employee = new employee();
  
         $employee-&gt;namedropdown = implode(',', $request-&gt;input('namedropdown')); //Already save multi-select dropdown ids to the database 
  
         $employee-&gt;save();
  
   $employee_team = new employee_team();
  
        $employee-&gt;teams()-&gt;attach($employee-&gt;namedropdown);
  
        return redirect()-&gt;route('employee.index')-&gt;with('success','Data Added');
  }
  </code></pre>
  
  <p>Error comes as <code>SQLSTATE[01000]: Warning: 1265 Data truncated for column 'team_id' at row 1</code></p>
  
  <p>Please help me to save employee_id and team_id to the "employee_teams" table. Thank you so much.</p>