📅  最后修改于: 2022-03-11 14:54:10.443000             🧑  作者: Mango
$user = User::find(2);
$roleIds = [1, 2];
$user->roles()->attach($roleIds);
$user = User::find(3);
$roleIds = [1, 2];
$user->roles()->sync($roleIds);