$this->id, 'reference' => $this->reference, 'reference_contract' => (int) $this->type, 'type' => (int) $this->type, 'status' => (int) $this->status, 'company_module' => new CompanyModuleResource($this->companyModule), 'warehouse' => new CompanyModuleResource($this->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee), 'address' => new AddressResource($this->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first()), 'address_change_request' => new AddressResource($this->addressesPendingVerification()->first()), 'storages' => $this->storages ? $this->storages : null, //from middleware 'remarks' => RemarkResource::collection($this->remarks), 'created_at' => $this->created_at->format('d-m-Y') ]; // if($this->include_invoices){ // $data['invoices'] = $this->whenLoaded('packingLists', function() { // return TransactionWithStorageResource::collection($this->transactions()->whereNotIn('transactions.status', [0, 1])->whereIn('transactions.type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->get()); // }); // } // if($this->include_parcels){ // $data['parcels'] = $this->whenLoaded('packingLists', function() { // return [ // 'origin_warehouse_packages' => PackingListResource::collection( // $this->originWarehousePackages()->get() // ), // 'in_transit_packages' => PackingListResource::collection( // $this->inTransitPackages()->get() // ), // 'destination_warehouse_packages' => PackingListResource::collection( // $this->destinationWarehousePackages()->get() // ), // 'delivered_packages' => PackingListResource::collection( // $this->deliveredPackages()->get() // ), // 'received_packages' => PackingListResource::collection($this->packingLists()->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('packages')->get()), // ]; // }); // } return $data; //OrderResource // return [ // 'invoices' => $this->whenLoaded('packingLists', function() use ($orderId) { // return TransactionResource::collection($this->transactions()->whereNotIn('transactions.status', [0, 1])->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get()); // }), // ]; } }