diff --git a/app/Http/Controllers/BrandController.php b/app/Http/Controllers/BrandController.php index b957fcf..b11a39a 100644 --- a/app/Http/Controllers/BrandController.php +++ b/app/Http/Controllers/BrandController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Brands\StoreBrandRequest; use App\Http\Requests\Brands\UpdateBrandRequest; use App\Models\Brand; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; @@ -38,6 +39,10 @@ class BrandController extends Controller $this->sortQuery($query); $searchFields = trans('Nom'); + $query->withCount(['customerInfos', 'customerInfos as customer_infos_optin_count' => function (Builder $q) { + $q->where('opt_in', true); + }]); + $brandModels = $query->paginate(12); return view('brands.index', compact('brandModels', 'searchFields')); diff --git a/resources/views/brands/index-list.blade.php b/resources/views/brands/index-list.blade.php index d734c5f..b61b77d 100644 --- a/resources/views/brands/index-list.blade.php +++ b/resources/views/brands/index-list.blade.php @@ -16,8 +16,8 @@ @foreach ($brandModels as $brandModel) {{ $brandModel->name }} - {{ count(\App\Models\CustomerInfo::where('brand_id', 'LIKE', $brandModel->id)->get()) }} - {{ count(\App\Models\CustomerInfo::where('brand_id', 'LIKE', $brandModel->id)->where('opt_in', true)->get()) }} + {{ $brandModel->customer_infos_count }} + {{ $brandModel->customer_infos_optin_count }} {{ $brandModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }}