user()->type, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]); $userType = Auth() && Auth()->user() ? Auth()->user()->type : RoleTypes::USER; $exceptionUsers = in_array($userType, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]); $data = [ 'id' => $this->id, 'claimant_id' => $this->claimant_id, 'status' => $this->status, 'transport' => new TransportResource($this->transports()->first()), 'type' => $this->type, 'container' => new ContainerResource($this->containers->first()), $this->mergeWhen($this->owner instanceof Order, [ 'order' => New OrderResource($this->owner) ]), ]; $packages = !$this->packingLists()->exists() || $exceptionUsers ? $this->packages : $this->packingLists->first()->packages; $data['packages'] = PackageReceivedResource::collection($packages); return $data; } }