Edit File: OrderResource.php
<?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; use App\Traits\GeneralTrait; use App\Models\Paymentmethod; use App\Models\Category; use App\Models\Setting; use App\Models\Review; use App\Http\Resources\OrderProductResource; use App\Http\Resources\StoresResource; use App\Http\Resources\StoreResource; use App\Http\Resources\DeliveryOffersResource; use App\Http\Resources\PaymentmethodResource; use App\Services\OrderService; use Carbon\Carbon; use App\Models\Order; class OrderResource extends JsonResource { use GeneralTrait; /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $lang = $request->header('lang') ?? 'ar'; //user $user = auth('api')->user(); // paymrnt method $payment_method = Paymentmethod::where('key',$this->payment_type)->first(); // order products $orderproducts = $this->orderproducts; // order current status if($this->user_id == $user->id){ $status = $this->statusForUser(); }else{ $status = $this->statusForStore(); } //image and name $image = ''; $name = ''; $image = $this->store_icon?$this->store_icon:''; $name = $this->store->getTranslations('name')[$lang]??''; $rate = Review::where('order_id',$this->id)->where('user_id' , $user->id)->first(); $is_rated = false; if ($rate) { $is_rated = true; } $store = $this->store; $original = $this->close_reason; return [ 'id' => $this->id, 'created_at' => $this->created_at->isoFormat('YYYY - MMMM - D'), 'status' => $status, 'deliver_time' => ($this->deliver_time) ? Carbon::createFromFormat('H:i:s', $this->deliver_time)->format('g:i A') : '', 'deliver_date' => ($this->deliver_date) ? Carbon::parse($this->deliver_date)->isoFormat('YYYY - MMMM - D') : '', 'payment_method' => new PaymentmethodResource($payment_method), 'payment_status' => $this->payment_status=='true'?true:false, 'have_invoice' => $this->have_invoice=='true'?true:false, 'needs_delivery' => $this->needs_delivery=='true'?true:false, 'type' => $this->type??'special_stores', 'price' => number_format($this->price,2)??'0', 'app_percentage' => number_format($this->app_percentage,2)??'0', 'added_value' => number_format($this->added_value,2)??'0', 'discount' => number_format($this->discount,2)??'0', 'total_price' => number_format($this->total_price,2)??'0', 'description' => $this->description??'', 'products' => OrderProductsResource::collection($orderproducts), 'user_id' => $this->user?$this->user->id:'', 'user_name' => $this->user?$this->user->name:'', 'user_phone' => $this->user?$this->user->country_key.$this->user->phone:'', 'user_avatar' => $this->user?$this->user->avatarPath:'', 'store' => new StoresResource($store), 'close_reason' => ($this->close_reason_trans ? trans('order.'.$this->close_reason_trans) : $this->close_reason)??'', 'rate_comment' => $rate ? $rate->comment : '', 'rate' => $rate ? $rate->rate : '', 'image' => $image, 'name' => $name, 'is_rated' => $is_rated, 'is_delivered' => ($this->store_status == 'delivered' && $this->status != 'finished') ? true : false ]; } }
Back to File Manager