fix: add eager loading for product images in BrandController
Fixes lazy loading violation on Product.images relation which was
causing BrandDashboardTest failures. Added `with('images')` eager
loading in both the dashboard method and calculateBrandInsights.
This commit is contained in:
@@ -145,8 +145,8 @@ class BrandController extends Controller
|
||||
{
|
||||
$this->authorize('view', [$brand, $business]);
|
||||
|
||||
// Load relationships
|
||||
$brand->load(['business', 'products']);
|
||||
// Load relationships (include images to avoid lazy loading in view)
|
||||
$brand->load(['business', 'products.images']);
|
||||
|
||||
// Get stats data for Analytics tab (default to this month)
|
||||
$preset = $request->input('preset', 'this_month');
|
||||
@@ -1721,7 +1721,8 @@ class BrandController extends Controller
|
||||
*/
|
||||
private function calculateBrandInsights(Brand $brand, Business $business, $startDate, $endDate): array
|
||||
{
|
||||
$products = $brand->products;
|
||||
// Eager load images to avoid N+1 and lazy loading errors
|
||||
$products = $brand->products()->with('images')->get();
|
||||
|
||||
// Top Performer - product with highest revenue in date range
|
||||
$topPerformer = null;
|
||||
|
||||
Reference in New Issue
Block a user