$this->id, 'container_reference' => $this->reference, 'container_specification' => ContainerTypes::CONTAINER_SPECIFICATION[$this->container_type], 'container_number' => $this->container_number, 'seal_reference' => $this->seal_reference, 'loading_date' => $this->loading_date ? $this->loading_date->format('d-m-Y') : $this->loading_date, 'transport' => new TransportResource($this->transports()->first()), 'packages_count' => $this->packages()->where('packages.type', '!=', 2)->sum('quantity'), 'total_cbm' => $this->packages()->sum(DB::raw('(width/100) * (height/100) * (length/100) * quantity')), 'remarks' => RemarkResource::collection($this->remarks), 'status' => $this->status, 'packing_lists' => $this->whenLoaded('packingLists', PackingListResource::collection($this->whenLoaded('packingLists', function(){ return $this->packingLists()->whereHas('packages')->get()->sortBy(function ($packingList) { return $packingList->owner->company_module_id; }); }))) ]; } }