Laravel : Many to many insertion Laravel : Many to many insertion php php

Laravel : Many to many insertion


You should pass an array of user IDs to the attach() method.

For convenience, attach and detach also accept arrays of IDs as input

Change your code to:

$team = \App\Team::findOrFail($request->team_id);$team->teamMembers()->attach($request->members_id);