Skip to content

Conversation

josedaian
Copy link

This PR enhances the syncRoles() method to dispatch RoleDetached events when roles are removed, but only if events are enabled via configuration.
When events are disabled, the method still uses the optimized detach() path to avoid unnecessary queries and maintain performance.

Changes

  • Updated syncRoles() to:
    • Use removeRole($currentRoles) when events are enabled, triggering RoleDetached.
    • Keep the original detach() implementation when events are disabled.
  • Added tests to confirm that:
    • RoleDetached is dispatched on syncRoles() when events are enabled.
    • Query count remains minimal when events are disabled.

Why

  • Improves consistency: syncRoles() now behaves like removeRole() in terms of event dispatching.
  • Allows consumers to listen for role detachment events in both removeRole() and syncRoles() scenarios.
  • Preserves backward compatibility and performance when events are disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant