Closed MohammedElattar closed 1 year ago
in ProductController, I eager load translation relationship, but when I use whenLoaded in a resource with specifying a default value for translation, it causes N+1 queries.
ProductController
whenLoaded
'translation' => $this->whenLoaded( 'translation', new ProductTranslationResource($this->translation) ), 'translations' => $this->whenLoaded( 'translations', ProductTranslationResource::collection($this->translations) ),
but it works if I don't pass a default value in whenLoaded method or using the following code:
if($this->relationLoaded('translation')){ $resource['translation'] = new ProductTranslationResource($this->translation); } if($this->relationLoaded('translations')){ $resource['translations'] = ProductTranslationResource::collection($this->translations); }
Great Work. ❤
This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days
in
ProductController
, I eager load translation relationship, but when I usewhenLoaded
in a resource with specifying a default value for translation, it causes N+1 queries.but it works if I don't pass a default value in
whenLoaded
method or using the following code:Great Work. ❤