feat: add UserLevel enum and integrate it in User Modal, UserResource and UserFactory

This commit is contained in:
idevakk
2025-11-17 08:34:07 -08:00
parent bbbaf3a234
commit 23cfd0c88d
5 changed files with 235 additions and 32 deletions

View File

@@ -2,6 +2,7 @@
namespace Database\Factories;
use App\enum\UserLevel;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
@@ -30,7 +31,7 @@ class UserFactory extends Factory
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'level' => 0,
'level' => UserLevel::NORMALUSER->value,
];
}
@@ -43,4 +44,35 @@ class UserFactory extends Factory
'email_verified_at' => null,
]);
}
/**
* Create a super admin user.
*/
public function superAdmin(): static
{
return $this->state(fn (array $attributes): array => [
'level' => UserLevel::SUPERADMIN->value,
'email' => 'admin@zemail.me',
]);
}
/**
* Create a normal user.
*/
public function normalUser(): static
{
return $this->state(fn (array $attributes): array => [
'level' => UserLevel::NORMALUSER->value,
]);
}
/**
* Create a banned user.
*/
public function bannedUser(): static
{
return $this->state(fn (array $attributes): array => [
'level' => UserLevel::BANNEDUSER->value,
]);
}
}