Edit File: OrderDetailsResource.php
<?php namespace App\Http\Resources\Api\User\Orders; use App\Enums\OrderPayStatus; use App\Enums\OrderStatusEnum; use App\Http\Resources\Api\General\Settings\CancelReasonResource; use App\Http\Resources\Api\Provider\OrdersItemResource; use App\Http\Resources\Api\User\Basics\BasicDelegateResource; use App\Http\Resources\Api\User\Basics\BasicProviderResource; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; class OrderDetailsResource extends JsonResource { public function toArray($request) { return [ 'id' => $this?->id, 'order_number' => $this?->order_num, 'receiving_method' => $this->receiving_method, 'status' => $this?->status, 'notes' => $this?->notes, 'order_call_type' => 'order', // When Order is Scheduled 'schedule_execution_date' => $this?->schedule_execution_date, 'schedule_execution_time' => $this?->schedule_execution_time, // Financial Transactions 'financial_transactions' => [ 'created_at' => $this->created_at->translatedFormat('j F Y'), 'coupon_num' => $this?->coupon_num, 'coupon_type' => $this?->coupon_type, 'coupon_value' => $this?->coupon_value, 'vat_per' => $this?->vat_per, 'vat_amount' => $this?->vat_amount, 'coupon_amount' => $this?->coupon_amount, 'total_products' => $this?->total_products, 'total_products_before_discount' => $this?->coupon_amount != 0 ? number_format($this?->total_products + $this?->coupon_amount, 2) : null, 'total_products_after_discount' => $this?->coupon_amount != 0 ? number_format($this?->total_products - $this?->coupon_amount, 2) : null, 'delivery_price' => $this?->delivery_price, 'final_total' => $this?->final_total, 'pay_type' => $this?->pay_type, 'pay_status' => $this?->pay_status, ], // When Receiving in Store 'car_color' => $this?->car_color, 'car_model' => $this?->car_model, 'car_plat_number' => $this?->car_plat_number, 'receiving_in_store_notes' => $this?->receiving_in_store_notes, // Informations 'provider' => BasicProviderResource::make($this?->provider), 'delegate' => BasicDelegateResource::make($this?->delegate), // Address Details 'map_desc' => $this?->map_desc, // Order Items 'order_items' => OrdersItemResource::collection($this?->orderItems), // When Cancelling 'cancellation_reason' => (is_null($this?->cancellationReason) && $this->status['value'] == OrderStatusEnum::Cancelled->value) ? [ 'id' => 0, 'reason' => __('apis.cancel_because_proider_dont_respond') ] : CancelReasonResource::make($this?->cancellationReason), // Order Time To cancel $this->mergeWhen($this->status['value'] == OrderStatusEnum::New->value, [ 'current_time' => Carbon::now()->format('Y-m-d H:i:s'), 'minutes_for_order_approval' => $this->expiry_period, 'expired_at' => Carbon::parse($this->expired_at)->format('Y-m-d H:i:s'), 'created_at_time' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'), ]), $this->mergeWhen($this->pay_status == OrderPayStatus::PAID->value, [ 'invoice_share_link' => route('user.normal_order.invoice', $this->order_num), ]), 'room_id' => $this->room?->id ?? $this->room_id, 'live_call' => [ 'api_key' => $this->api_key, 'session_id' => $this->session_id, 'token' => $this->token, 'secret_key' => $this->secret_key, ], 'currency' => __('site.currency'), 'is_rated' => $this->rates()?->where([ 'ratingable_id' => auth('user')->id(), 'ratingable_type' => get_class(auth()->user()) ])->exists() ]; } }
Back to File Manager