Replies: 2 comments
-
Maybe better public function permissions(): BelongsToMany
{
return parent::permissions()->using(DefaultPivot::class);
} Authors wants to keep the package simple |
Beta Was this translation helpful? Give feedback.
0 replies
-
Went back to this just now.. I realize overwriting the trait method This method detaches everything first, and follows up with permission/role assignment. An event here would still be nice to keep things clean imo. Something like public function syncPermissions(...$permissions)
{
$oldPermissions = $this->permissions->pluck('name')->flatten();
$newPermissions = collect($permissions)->flatten();
$this->permissions()->detach();
$this->givePermissionTo($permissions);
PermissionChangeEvent::dispatch($oldPermissions, $newPermissions);
// Or maybe more usefull
// $revoked = $oldPermissions->diff($newPermissions);
// if ($revoked->isNotEmpty()) {
// PermissionsRevokedEvent::dispatch($revoked);
// }
return $this;
} Nothing too fancy or complicated. Anyway, it's also solvable without. Feel free to close if there is no interest. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Edit:
The original idea for a pivot model stemmed from having more control. I've reformulated this using an event here
Original:
Beta Was this translation helpful? Give feedback.
All reactions