type = $type; $this->item = match ($type) { 'perfume' => Perfume::byHash($hash), 'product' => Product::byHash($hash), 'bottle' => Bottle::byHash($hash), default => null, }; if (! $this->item) { abort(404); } $this->activityLogs = Activity::where('subject_type', get_class($this->item)) ->where('subject_id', $this->item->id) ->latest() ->get() ->map(function (Activity $activity) { $status = match ($activity->event) { 'increase' => AuditStockStatus::INCREASED, 'decrease' => AuditStockStatus::DECREASED, 'created' => AuditStockStatus::INCREASED, 'updated' => AuditStockStatus::UPDATED, 'deleted' => AuditStockStatus::DELETED, default => AuditStockStatus::tryFrom($activity->event), }; $color = $status?->color() ?? 'gray'; $label = $status?->label() ?? ucfirst($activity->event); $classes = match ($color) { 'emerald' => 'bg-emerald-200 text-emerald-800 dark:bg-emerald-800 dark:text-emerald-200', 'orange' => 'bg-orange-200 text-orange-800 dark:bg-orange-800 dark:text-orange-200', 'yellow' => 'bg-yellow-200 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-200', 'red' => 'bg-red-200 text-red-800 dark:bg-red-800 dark:text-red-200', default => 'bg-gray-200 text-gray-800 dark:bg-gray-800 dark:text-gray-200', }; $activity->event = [ 'label' => $label, 'color' => $color, 'classes' => $classes, ]; return $activity; }); } public function render(): View { return view('livewire.studio.stock.inventory-history.show'); } }