feat: optimize category and product resource queries with eager loading and response formatting improvements

This commit is contained in:
2026-06-29 14:35:20 -03:00
parent 59ed592787
commit b05a574610
4 changed files with 16 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ class CategoryController extends Controller
})
->with(['parent', 'subCategories', 'tenant'])
->orderByDesc('id')
->paginateFromRequest()
->get()
)->response();
}

View File

@@ -20,7 +20,11 @@ class ProductController extends Controller
return ProductResource::collection(
Product::query()
->where('tenant_codigo', $tenant->codigo)
->with(['attachments', 'brand', 'category'])
->with([
'attachments' => fn ($query) => $query->orderBy('attachments.id')->limit(1),
'brand',
'category',
])
->latest()
->paginateFromRequest()
)->response();