Edit File: StoreResource.php
<?php namespace App\Http\Resources; use App\Http\Resources\ProductsResource; use App\Http\Resources\StoreMenuGoogleResource; use App\Http\Resources\StoreMenuCategoriesResource; use App\Models\Category; use App\Traits\ApiTrait; use App\Traits\GeneralTrait; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use App\Models\StoreMenu; class StoreResource extends JsonResource { use GeneralTrait, ApiTrait; /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $user =auth('api')->user(); $bank_number = ''; $iban_number =''; $commercial_id=''; if( $user && $user->type == 'store') { $bank_number = $this->bank_number ?? ''; $iban_number = $this->iban_number ?? ''; $commercial_id=$this->commercial_id ?? ''; } // $page = $request['page'] ?? 1; // $products=[]; // $pagination=''; $lang = $request->header('lang') ?? 'ar'; $menu_categories = $this->menuCategories ?? ''; $menu_images = StoreMenu::where('store_id',$this->id)->get(); $menu_images = StoreMenuGoogleResource::collection($menu_images); // $category = Category::where('slug', $this->category)->first(); return [ 'id' => $this->id, 'is_open' => $this->has_contract == false ? true : $this->openingHours($lang)['open_status'], 'delivery_price' => $this->deliveryPrice($this->distance)['display_delivery_price'] . ' ' . trans('stores.sar'), 'name' => $this->name ?? '', 'desc' => $this->desc ?? '', 'icon' => $this->icon ? $this->iconPath : '', 'cover' => $this->cover ? $this->coverPath : '', 'lat' => $this->lat ?? '', 'long' => $this->long ?? '', 'address' => $this->address ?? '', 'num_rating' => $this->num_rating ?? 0, 'rate' => $this->rate ? number_format($this->rate,1): '0.0', 'category' => $this->category ?? '', 'iban_number' => $iban_number??'', 'bank_number' => $bank_number??'', 'commercial_id' => $commercial_id ??'', 'offer' => $this->offer == 'true' ? true : false, 'offer_image' => $this->offer_image ? $this->offerPath : '', 'offer_amount' => (string) $this->offer_amount ?? '0', 'offer_type' => (string) $this->offer_type ?? '', 'offer_max' => (string) $this->offer_max ?? '', 'available' => (string) $this->available == 'true' ? true : false, 'has_contract' => ((string) $this->has_contract == 'true' ||(string) $this->has_contract == '1' ) ? true : false, 'distance' => (number_format((float) $this->distance, 2, '.', '') ?? '0.00') . ' ' . trans('stores.km'), 'opening_hours' => $this->openingHours($lang)['opening_hours_arr'] ?? '', 'memu' => StoreMenuCategoriesResource::collection($menu_categories), 'branch_country_key' => $this->user->country_key ?? '', 'branch_phone' => $this->user->phone ?? '', 'branch_email' => $this->user->email ?? '', 'menu_images' => $menu_images, // 'products' => $products, // 'pagination' => $pagination, ]; } }
Back to File Manager