Answers for "laravel many to many add new record"

PHP
0

laravel many to many insert data

$user = User::find(2);   
$roleIds = [1, 2];
$user->roles()->attach($roleIds);

$user = User::find(3);   
$roleIds = [1, 2];
$user->roles()->sync($roleIds);
Posted by: Guest on May-17-2021
0

laravel add many to many

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 = AppTeam::findOrFail($request->team_id);
$team->teamMembers()->attach($request->members_id);
Posted by: Guest on January-06-2022

Code answers related to "laravel many to many add new record"

Browse Popular Code Answers by Language