Edit File: UserResource.php
<?php namespace App\Http\Resources; use App\Http\Requests\Admin\fqs\store; use App\Models\City; use App\Models\Country; use App\Models\Region; use Illuminate\Http\Resources\Json\JsonResource; use App\Traits\GeneralTrait; class UserResource extends JsonResource { use GeneralTrait; /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $user = auth('api')->user(); if($user && $user->type == 'store') { $store = $user->store; $rate = $store->rate ?? '0.0' ; }else{ $rate = $this->rate??'0.0'; } if($this->type == 'delegate') { $join_request = $this->delegateJoinRequests()->first(); $avatar = asset('assets/uploads/users/'.$join_request->personal_image) ?? $this->avatarPath ; $region = $join_request->region_id; $city = $join_request->city_id; }else{ $avatar = $this->avatarPath??''; $region = $this->region_id; $city = $this->city_id; } $country = Country::where('calling_code', $this->country_key)->first(); return [ 'id' => $this->id, 'name' => $this->name??'', 'email' => $this->email??'', 'completed_info' => $this->completed_info =='true'?true:false, 'country_key' => $this->country_key??'', 'country_flag' => $country ? $country->flag_path : '', 'phone' => $this->full_phone, 'changed_phone' => $this->changed_phone?$this->fullChangedPhone:'', 'avatar' => $this->avatarPath??'', 'lat' => $this->lat??'', 'long' => $this->long??'', 'address' => $this->address??'', 'rate' => $rate, 'wallet' => (string)$this->wallet??'0', 'total_bills' => (string)$this->total_bills??'0', 'total_delivery_fees' => (string)$this->total_delivery_fees??'0', 'num_orders' => (string)$this->num_orders??'0', 'num_comments' => (string)$this->num_comments??'0', 'acc_type' => $this->type??'user', 'new_orders_notify' => $this->new_orders_notify=='true'?true:false, 'offers_notify' => $this->offers_notify=='true'?true:false, 'time_zone' => date_default_timezone_get(), 'date' => date_format(date_create($this->created_at), 'Y-m-d'), 'gender' => $this->gender, 'nationality_id' => (int)$this->nationality_id, 'region_id' => (int)$region ?? '', 'city_id' => (int)$city ?? '', 'sound_notify' => $this->notify_sound == 'true'?true:false, ]; } }
Back to File Manager