'boolean', 'admission_date' => 'datetime', 'discharge_date' => 'datetime', ]; protected static function boot() { parent::boot(); static::creating(function (self $model) { if (empty($model->uuid)) { $model->uuid = (string) Str::orderedUuid(); } if (empty($model->code)) { $model->code = self::getNextCode(); } }); } public static function getNextCode(): string { $lastCode = (string) self::withTrashed()->max('code'); preg_match('/(\d+)$/', $lastCode, $matches); $nextNumber = isset($matches[1]) ? ((int) $matches[1] + 1) : (self::withTrashed()->count() + 1); return self::makeCode($nextNumber); } public static function makeCode(int $nextNumber): string { return self::$codePrefix . '-' . str_pad((string) $nextNumber, 5, '0', STR_PAD_LEFT); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function member() { return $this->belongsTo(Member::class, 'member_id'); } public function plan() { return $this->belongsTo(Plan::class, 'plan_id'); } public function requestLogBenefits() { return $this->hasMany(RequestLogBenefit::class, 'request_log_id'); } }