id = (int) ($data['id'] ?? 0); $itemType->name = $data['name'] ?? ''; $itemType->slug = $data['slug'] ?? ''; $itemType->description = $data['description'] ?? ''; $itemType->icon = isset($data['icon']) ? (is_array($data['icon']) ? $data['icon'] : maybe_unserialize($data['icon'])) : null; $itemType->color = $data['color'] ?? 'blue'; $itemType->status = $data['status'] ?? 'draft'; $itemType->created_at = $data['created_at'] ?? ''; $itemType->updated_at = $data['updated_at'] ?? ''; $itemType->created_by = (int) ($data['created_by'] ?? 0); $itemType->updated_by = (int) ($data['updated_by'] ?? 0); return $itemType; } /** * Convert to array */ public function toArray(): array { return [ 'id' => $this->id, 'name' => $this->name, 'slug' => $this->slug, 'description' => $this->description, 'icon' => $this->icon, 'color' => $this->color, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, ]; } }