File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,4 +116,19 @@ public function getGuardName(): string
116116 {
117117 return $ this ->guard_name ;
118118 }
119+
120+ /**
121+ * Roles que tienen este permiso (roles.permission_ids es un array plano de ids).
122+ */
123+ public function roles (): \Illuminate \Support \Collection
124+ {
125+ $ roleClass = config ('permission.models.role ' );
126+ return $ roleClass ::query ()->where ('permission_ids ' , (string ) $ this ->getKey ())->get ();
127+ }
128+
129+ /** Acceso por propiedad: $permission->roles (paridad Spatie/Maklad). */
130+ public function getRolesAttribute (): \Illuminate \Support \Collection
131+ {
132+ return $ this ->roles ();
133+ }
119134}
Original file line number Diff line number Diff line change @@ -117,6 +117,37 @@ public function permissions(): Collection
117117 return $ permClass ::query ()->whereIn ('_id ' , $ this ->permission_ids ?? [])->get ();
118118 }
119119
120+ /**
121+ * Usuarios que tienen este rol. Soporta role_ids plano (["id"]) y
122+ * estructurado ([{role_id: "id"}]) para compatibilidad con datos legacy.
123+ */
124+ public function users (): Collection
125+ {
126+ $ userClass = config ('auth.providers.users.model ' );
127+ if (! $ userClass ) {
128+ return collect ();
129+ }
130+ $ id = (string ) $ this ->getKey ();
131+ return $ userClass ::query ()
132+ ->where (function ($ q ) use ($ id ): void {
133+ $ q ->where ('role_ids ' , $ id )
134+ ->orWhere ('role_ids.role_id ' , $ id );
135+ })
136+ ->get ();
137+ }
138+
139+ /** Acceso por propiedad: $role->users (paridad Spatie/Maklad). */
140+ public function getUsersAttribute (): Collection
141+ {
142+ return $ this ->users ();
143+ }
144+
145+ /** Acceso por propiedad: $role->permissions (paridad Spatie/Maklad). */
146+ public function getPermissionsAttribute (): Collection
147+ {
148+ return $ this ->permissions ();
149+ }
150+
120151 public function givePermissionTo (...$ permissions ): self
121152 {
122153 $ ids = $ this ->resolvePermissionIds ($ this ->flatten ($ permissions ));
Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ public function permissions()
2020 return $ permClass ::query ()->whereIn ('_id ' , $ ids )->get ();
2121 }
2222
23+ /** Acceso por propiedad: $user->permissions (paridad Spatie/Maklad). */
24+ public function getPermissionsAttribute (): \Illuminate \Support \Collection
25+ {
26+ return $ this ->permissions ();
27+ }
28+
2329 public function givePermissionTo (...$ permissions ): self
2430 {
2531 return $ this ->attachPermissions ($ this ->flattenInput ($ permissions ), null );
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ public function roles(): Collection
2323 return $ roleClass ::query ()->whereIn ('_id ' , $ ids )->get ();
2424 }
2525
26+ /** Acceso por propiedad: $user->roles (paridad Spatie/Maklad). */
27+ public function getRolesAttribute (): Collection
28+ {
29+ return $ this ->roles ();
30+ }
31+
2632 public function assignRole (...$ roles ): self
2733 {
2834 return $ this ->attachRoles ($ this ->flattenInput ($ roles ), null );
You can’t perform that action at this time.
0 commit comments