📜  laravel 多对多插入数据 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:10.443000             🧑  作者: Mango

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

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