I have a method called show at the Product Model which returns a resource for api results:
public function show(Product $product): ProductResource
{
return (new ProductResource($product))->additional([
'gallery' => $product->photos->pluck('image')
->transform(fn ($v) => Storage::disk('public')->url($v))
]);
}
Now I have defined a method called similarProductsBasedOnBrand at the Product Model which goes like this:
public function similarProductsBasedOnBrand($brand_id)
{
return Category::find($brand_id)->products()->get();
}
But don’t know how to get results from this method in api result of show()!
So if you know how to return the results of similarProductsBasedOnBrand in the response of show method, please let me know… I really need this.
Thanks