1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

laravel select マルチ 保存方法 多対多テーブル利用

Posted at
        <select class="form-control select2" multiple="" name="items[]" >
         @foreach ($itemss as $item)
            <option value="{{ $item->id }}">{{ $item->name }}</option>
         @endforeach
        </select>

        --Model--
        TableA
        TableA_TableB
        TableB
        --Controller-
        
        foreach($request->items as $itemId) {
            $table_AB = new TableA_TableB();
            $table_AB->$table_a_id = $table_a->id;
            $table_AB->table_b_id = $itemId;
            $table_AB->save();
        }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?