label = $perfume->name.' di '.$warehouse->name; $this->activityLogs = Activity::where('subject_type', get_class($perfume)) ->where('subject_id', $perfume->id) ->where('properties->warehouse_id', $warehouse->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('components.sections.ui.audit', [ 'pageTitle' => 'Audit '.$this->label, 'backRoute' => route('studio.master.warehouse.show', ['warehouse' => request()->route('warehouse')]), ]); } }