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);
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);
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);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us