diff --git a/app/Enums/EmploymentStatus.php b/app/Enums/EmploymentStatus.php new file mode 100644 index 0000000..4f3eb9c --- /dev/null +++ b/app/Enums/EmploymentStatus.php @@ -0,0 +1,33 @@ + 'Permanent', + self::CONTRACT => 'Contract', + self::INTERN => 'Intern', + }; + } + + public function color(): string + { + return match ($this) { + self::PERMANENT => 'primary', + self::CONTRACT => 'warning', + self::INTERN => 'secondary', + }; + } + + public static function values(): array + { + return array_map(fn ($case) => $case->value, self::cases()); + } +} diff --git a/app/Enums/Gender.php b/app/Enums/Gender.php new file mode 100644 index 0000000..a9468b7 --- /dev/null +++ b/app/Enums/Gender.php @@ -0,0 +1,30 @@ + 'Male', + self::FEMALE => 'Female', + }; + } + + public function color(): string + { + return match ($this) { + self::MALE => 'primary', + self::FEMALE => 'success', + }; + } + + public static function values(): array + { + return array_map(fn ($case) => $case->value, self::cases()); + } +} diff --git a/app/Enums/UserStatus.php b/app/Enums/UserStatus.php new file mode 100644 index 0000000..008676e --- /dev/null +++ b/app/Enums/UserStatus.php @@ -0,0 +1,33 @@ + 'Active', + self::INACTIVE => 'Inactive', + self::SUSPENDED => 'Suspended', + }; + } + + public function color(): string + { + return match ($this) { + self::ACTIVE => 'primary', + self::INACTIVE => 'warning', + self::SUSPENDED => 'danger', + }; + } + + public static function values(): array + { + return array_map(fn ($case) => $case->value, self::cases()); + } +} diff --git a/app/Models/Employee.php b/app/Models/Employee.php new file mode 100644 index 0000000..06398b2 --- /dev/null +++ b/app/Models/Employee.php @@ -0,0 +1,33 @@ + Gender::class, + 'birthdate' => 'date', + 'hire_date' => 'date', + 'resign_date' => 'date', + 'status' => EmploymentStatus::class, + ]; + } + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 749c7b7..a8d8ffb 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,46 +3,31 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; + +use App\Enums\UserStatus; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { - /** @use HasFactory<\Database\Factories\UserFactory> */ - use HasFactory, Notifiable; + use HasFactory, Notifiable, SoftDeletes; - /** - * The attributes that are mass assignable. - * - * @var list - */ - protected $fillable = [ - 'name', - 'email', - 'password', - ]; + protected $guarded = ['id']; - /** - * The attributes that should be hidden for serialization. - * - * @var list - */ - protected $hidden = [ - 'password', - 'remember_token', - ]; - - /** - * Get the attributes that should be cast. - * - * @return array - */ protected function casts(): array { return [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', + 'last_login_at' => 'datetime', + 'last_password_change_at' => 'datetime', + 'status' => UserStatus::class, ]; } + + public function employee(): HasOne + { + return $this->hasOne(Employee::class); + } } diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 05fb5d9..03decb4 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -1,5 +1,6 @@ id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); + $table->string('email', 100)->unique(); + $table->string('username', 20)->unique(); + $table->string('phone_number', 20); + $table->string('password', 97); + $table->timestamp('last_login_at')->nullable(); + $table->timestamp('last_password_change_at')->nullable(); + $table->enum('status', [UserStatus::values()])->default(UserStatus::INACTIVE); $table->timestamps(); + $table->softDeletes(); }); Schema::create('password_reset_tokens', function (Blueprint $table) { diff --git a/database/migrations/2025_09_13_034842_create_employees_table.php b/database/migrations/2025_09_13_034842_create_employees_table.php new file mode 100644 index 0000000..56fefd0 --- /dev/null +++ b/database/migrations/2025_09_13_034842_create_employees_table.php @@ -0,0 +1,40 @@ +id(); + $table->foreignId('user_id')->constrained()->cascadeOnDelete(); + $table->string('code', 50)->unique(); + $table->string('full_name', 100); + $table->enum('gender', [Gender::values()]); + $table->date('birthdate'); + $table->date('hire_date'); + $table->date('resign_date')->nullable(); + $table->enum('status', [EmploymentStatus::values()])->default(EmploymentStatus::PERMANENT); + $table->unsignedInteger('base_salary')->default(0); + $table->text('address'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('employees'); + } +};