Laravel的Laratrust包中syncPermissions()
和attachPermissions()
之间有什么区别?
$role->attachPermissions($permission);
和
$role->syncPermissions($permission);
答案 0 :(得分:1)
这些差异与Laravel的多对多关系的本地attach()
和sync()
方法相同。
答案 1 :(得分:0)
$admin->attachPermission($createPost);
// parameter can be a Permission object, array or id
// equivalent to $admin->permissions()->attach([$createPost->id]);
...
$owner->attachPermissions([$createPost, $editUser]);
// parameter can be a Permission object, array or id
// equivalent to $owner->permissions()->attach([$createPost->id, $editUser->id]);
...
$owner->syncPermissions([$createPost, $editUser]);
// parameter can be a Permission object, array or id
// equivalent to $owner->permissions()->sync([$createPost->id, $editUser->id]);