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(); $is_selected = false; if($user && $user->type == 'store' && $user->store->category == $this->slug|| $user && $user->type == 'store' && 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 , 'have_sub' => $this->subcategories()->count() > 0 ? true : false, ]; } }
Back to File Manager