feat: implement super admin role with spatie rbac and categorize sidebar by management
This commit is contained in:
@@ -26,6 +26,7 @@ class UserFactory extends Factory
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'username' => fake()->unique()->userName(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
@@ -42,4 +43,19 @@ class UserFactory extends Factory
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*/
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterCreating(function (User $user) {
|
||||
if ($user->role && \Illuminate\Support\Facades\Schema::hasTable('roles')) {
|
||||
$role = \Spatie\Permission\Models\Role::where('name', $user->role)->first();
|
||||
if ($role && !$user->hasRole($user->role)) {
|
||||
$user->assignRole($role);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user