@@ -43,7 +43,7 @@ public static function create(array $attributes = [])
4343 if (array_key_exists (PermissionRegistrar::$ teamsKey , $ attributes )) {
4444 $ params [PermissionRegistrar::$ teamsKey ] = $ attributes [PermissionRegistrar::$ teamsKey ];
4545 } else {
46- $ attributes [PermissionRegistrar::$ teamsKey ] = app (PermissionRegistrar::class)-> getPermissionsTeamId ();
46+ $ attributes [PermissionRegistrar::$ teamsKey ] = getPermissionsTeamId ();
4747 }
4848 }
4949 if (static ::findByParam ($ params )) {
@@ -131,21 +131,24 @@ public static function findOrCreate(string $name, $guardName = null): RoleContra
131131 $ role = static ::findByParam (['name ' => $ name , 'guard_name ' => $ guardName ]);
132132
133133 if (! $ role ) {
134- return static ::query ()->create (['name ' => $ name , 'guard_name ' => $ guardName ] + (PermissionRegistrar::$ teams ? [PermissionRegistrar::$ teamsKey => app (PermissionRegistrar::class)-> getPermissionsTeamId ()] : []));
134+ return static ::query ()->create (['name ' => $ name , 'guard_name ' => $ guardName ] + (PermissionRegistrar::$ teams ? [PermissionRegistrar::$ teamsKey => getPermissionsTeamId ()] : []));
135135 }
136136
137137 return $ role ;
138138 }
139139
140140 protected static function findByParam (array $ params = [])
141141 {
142- $ query = static ::when (PermissionRegistrar::$ teams , function ($ q ) use ($ params ) {
143- $ q ->where (function ($ q ) use ($ params ) {
142+ $ query = static ::query ();
143+
144+ if (PermissionRegistrar::$ teams ) {
145+ $ query ->where (function ($ q ) use ($ params ) {
144146 $ q ->whereNull (PermissionRegistrar::$ teamsKey )
145- ->orWhere (PermissionRegistrar::$ teamsKey , $ params [PermissionRegistrar::$ teamsKey ] ?? app (PermissionRegistrar::class)-> getPermissionsTeamId ());
147+ ->orWhere (PermissionRegistrar::$ teamsKey , $ params [PermissionRegistrar::$ teamsKey ] ?? getPermissionsTeamId ());
146148 });
147- });
148- unset($ params [PermissionRegistrar::$ teamsKey ]);
149+ unset($ params [PermissionRegistrar::$ teamsKey ]);
150+ }
151+
149152 foreach ($ params as $ key => $ value ) {
150153 $ query ->where ($ key , $ value );
151154 }
0 commit comments