File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,16 @@ public static function create(array $attributes = [])
4949 throw PermissionAlreadyExists::create ($ attributes ['name ' ], $ attributes ['guard_name ' ]);
5050 }
5151
52+ // Check for case-insensitive duplicate
53+ $ existing = static ::query ()
54+ ->whereRaw ('LOWER(name) = ? ' , [strtolower ($ attributes ['name ' ])])
55+ ->where ('guard_name ' , $ attributes ['guard_name ' ])
56+ ->first ();
57+
58+ if ($ existing ) {
59+ throw PermissionAlreadyExists::create ($ attributes ['name ' ], $ attributes ['guard_name ' ]);
60+ }
61+
5262 return static ::query ()->create ($ attributes );
5363 }
5464
Original file line number Diff line number Diff line change @@ -62,6 +62,24 @@ public static function create(array $attributes = [])
6262 throw RoleAlreadyExists::create ($ attributes ['name ' ], $ attributes ['guard_name ' ]);
6363 }
6464
65+ // Check for case-insensitive duplicate
66+ $ query = static ::query ()
67+ ->whereRaw ('LOWER(name) = ? ' , [strtolower ($ attributes ['name ' ])])
68+ ->where ('guard_name ' , $ attributes ['guard_name ' ]);
69+
70+ if ($ registrar ->teams ) {
71+ $ teamsKey = $ registrar ->teamsKey ;
72+ $ query ->where (fn ($ q ) => $ q ->whereNull ($ teamsKey )
73+ ->orWhere ($ teamsKey , $ params [$ teamsKey ] ?? getPermissionsTeamId ())
74+ );
75+ }
76+
77+ $ existing = $ query ->first ();
78+
79+ if ($ existing ) {
80+ throw RoleAlreadyExists::create ($ attributes ['name ' ], $ attributes ['guard_name ' ]);
81+ }
82+
6583 return static ::query ()->create ($ attributes );
6684 }
6785
You can’t perform that action at this time.
0 commit comments