email; $site->load("campagnes"); if ($email) { $customer = Customers::where('email', $email)->first(); if ($customer) { $publishedCampaign = $site->campagnes->where('camp_published', 1)->pluck('camp_id'); $campaigns = Campagne::where('camp_published', 1)->whereHas('printedWalls', function ($q) use ($customer, $publishedCampaign) { $q->where('customer_id', $customer->id)->whereIn('camp_id', $publishedCampaign); })->get(); } } return view('customers.index', compact('site', 'customer', 'campaigns', 'email')); } }