resolveCustomer($uuid); return Note::with('user:id,username') ->where('customer_id', $customer->id) ->whereNull('service_id') ->latest() ->get(); } public function storeCustomerNote(string $uuid, string $note, int $userId): Note { return $this->storeNote($uuid, ['note' => $note], $userId); } /** * Ghi chú gắn với 1 dịch vụ cụ thể của khách hàng. */ public function getServiceNotes(string $uuid, int $serviceId): Collection { $customer = $this->resolveCustomer($uuid); return Note::with('user:id,username') ->where('customer_id', $customer->id) ->where('service_id', $serviceId) ->latest() ->get(); } public function storeServiceNote(string $uuid, int $serviceId, string $note, int $userId): Note { return $this->storeNote($uuid, ['note' => $note, 'service_id' => $serviceId], $userId); } public function destroyNote(string $uuid, int $noteId): void { $customer = $this->resolveCustomer($uuid); $deleted = Note::where('id', $noteId)->where('customer_id', $customer->id)->delete(); abort_if(!$deleted, 404, 'Không tìm thấy ghi chú'); } private function storeNote(string $uuid, array $attributes, int $userId): Note { $customer = $this->resolveCustomer($uuid); $note = Note::create([ ...$attributes, 'customer_id' => $customer->id, 'user_id' => $userId, ]); return $note->load('user:id,username'); } }