addresses()->defaultAddress()->first(); /** @var CompanyModule $defaultAddress */ $defaultAddress = $defaultAddress ? $defaultAddress : $this->addresses()->first(); $connection = $this->inviters()->withPivot('invitee_reference')->first(); $marking = $connection ? $connection->pivot->invitee_reference:''; $segmentConstantObject = SegmentConstant::where('reference', SegmentConstants::WAREHOUSE_RATE)->get(); $segmentConstant = $segmentConstantObject->isEmpty() ? [] : (array)$segmentConstantObject->first()->value; return [ 'id' => $this->id, 'type' => $this->type, 'name' => $this->name, 'reference' => $this->reference, 'address' => new AddressResource($defaultAddress), 'company' => new CompanyResource($this->whenLoaded('company')), 'remarks' => RemarkResource::collection($this->remarks), 'marking' => $marking, 'warehouseCharges' => array_key_exists($this->id, $segmentConstant) ? $segmentConstant[$this->id] : null, 'connections' => $this->connections, ]; } }