Edit File: CategoriesResource.php
<?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; use App\Models\StoreCategory; class CategoriesResource extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $user = auth('api')->user(); $lang = $request->header('lang'); $is_selected = false; // $parentcategories = Category::where('category_id',$this->id)->first(); if($user && $user->type == 'store') { if($user->store->category == $this->slug) { $is_selected = true; }elseif (StoreCategory::where('store_id' , $user->store->id)->where('category_id' , $this->id)->first()){ $is_selected = true; } } return [ 'id' => $this->id, 'name' => $this->name??'', 'slug' => $this->slug??'', 'image' => $this->image?$this->ImagePath:'', 'is_selected' => $is_selected ?? false, ]; } }
Back to File Manager