`syncPermissions()`和`attachPermissions()`之间的区别?

时间:2018-03-29 05:30:52

标签: php laravel

Laravel的Laratrust包中syncPermissions()attachPermissions()之间有什么区别?

$role->attachPermissions($permission);

$role->syncPermissions($permission);

2 个答案:

答案 0 :(得分:1)

这些差异与Laravel的多对多关系的本地attach()sync()方法相同。

请参阅:Laravel Eloquent - Attach vs 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]);

来自Laratrust Docs