You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey,
first of all you can call with('translations') to prevent any n+1 query problem.
Secondly You should use Model::query()->pluck('id') if you only need a single column.
Next is that returning a model collection as response and using the models implicit array casting is bad practice. You should always use explicit resource classes for API/JSON responses: https://laravel.com/docs/8.x/eloquent-resources
And in case you need multiple columns which aren't translated and you haven't enabled loaded the translations it will not load them with explicit mapping as long as you don't use any translated attribute.
Your implicit array problem is likely an unwanted configuration on your end:
When I need to select non translatable fields for example only id and call Model::all(['id']) it still tries to load translations and runs N+1 query.
The text was updated successfully, but these errors were encountered: