Edit File: OrdersResource.php
<?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; use App\Models\Category; use App\Traits\GeneralTrait; class OrdersResource 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'; //auth $user = auth('api')->user(); //image and name $image = ''; $name = ''; if($user->type == 'store') { $image = $this->user->avatarPath ?? ''; $name = $this->user->name ?? ''; }else { $image = $this->store->icon ? $this->store->icon_path : ''; $name = $this->store?->getTranslations('name')[$lang] ?? ''; } // status if($this->user_id == $user->id){ $status = $this->statusForUser(); }elseif($this->delegate_id == $user->id ){ $status = $this->statusForDelegate(); }else{ $status = $this->statusForStore(); } return [ 'id' => $this->id, 'created_at' => $this->created_at->diffForHumans(), 'status' => $status, 'image' => $image, 'name' => $name, 'price' => number_format($this->price,2)??'0', 'user_name' => $this->user?->name??'', 'type' => $this->type, ]; } }
Back to File Manager