packingLists()->first(); $packages = $replica ? $replica->packages : $this->packages; if(Auth()->user()->type === RoleTypes::SHADOW_ADMIN) { $packages = $this->packages; } return [ 'id' => $this->id, 'claimant_id' => $this->claimant_id, 'reference' => $this->reference, 'status' => $this->status, 'transport' => new TransportResource($this->transports()->first()), 'type' => $this->type, 'packages' => PackageResource::collection($packages), 'packing_list' => new PackingListResource($replica), $this->mergeWhen($this->owner instanceof Order, [ 'order' => New OrderResource($this->owner) ]) ]; } }