id = (int) ($data['id'] ?? 0); $category->label = $data['label'] ?? ''; $category->slug = $data['slug'] ?? ''; $category->description = $data['description'] ?? ''; $category->age_min = isset($data['age_min']) && $data['age_min'] !== '' ? (int) $data['age_min'] : null; $category->age_max = isset($data['age_max']) && $data['age_max'] !== '' ? (int) $data['age_max'] : null; $category->pricing_mode = isset($data['pricing_mode']) && in_array($data['pricing_mode'], ['per_person', 'per_group'], true) ? $data['pricing_mode'] : 'per_person'; $category->min_pax = isset($data['min_pax']) && $data['min_pax'] !== '' ? (int) $data['min_pax'] : null; $category->max_pax = isset($data['max_pax']) && $data['max_pax'] !== '' ? (int) $data['max_pax'] : null; $category->group_overflow = isset($data['group_overflow']) && in_array($data['group_overflow'], ['block', 'per_block'], true) ? $data['group_overflow'] : 'block'; $category->icon = isset($data['icon']) ? (is_array($data['icon']) ? $data['icon'] : maybe_unserialize($data['icon'])) : null; $category->status = $data['status'] ?? 'draft'; $category->created_at = $data['created_at'] ?? ''; $category->updated_at = $data['updated_at'] ?? ''; $category->created_by = (int) ($data['created_by'] ?? 0); $category->updated_by = (int) ($data['updated_by'] ?? 0); return $category; } /** * Convert to array */ public function toArray(): array { return [ 'id' => $this->id, 'label' => $this->label, 'slug' => $this->slug, 'description' => $this->description, 'age_min' => $this->age_min, 'age_max' => $this->age_max, 'pricing_mode' => $this->pricing_mode, 'min_pax' => $this->min_pax, 'max_pax' => $this->max_pax, 'group_overflow' => $this->group_overflow, 'icon' => $this->icon, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, ]; } }