fix request brands customer count
This commit is contained in:
parent
fc26fe3f5a
commit
d206e3bf55
2 changed files with 7 additions and 2 deletions
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
@foreach ($brandModels as $brandModel)
|
||||
<tr>
|
||||
<td class="text-center align-middle bg-white">{{ $brandModel->name }}</td>
|
||||
<td class="text-center align-middle bg-white">{{ count(\App\Models\CustomerInfo::where('brand_id', 'LIKE', $brandModel->id)->get()) }}</td>
|
||||
<td class="text-center align-middle bg-white">{{ count(\App\Models\CustomerInfo::where('brand_id', 'LIKE', $brandModel->id)->where('opt_in', true)->get()) }}</td>
|
||||
<td class="text-center align-middle bg-white">{{ $brandModel->customer_infos_count }}</td>
|
||||
<td class="text-center align-middle bg-white">{{ $brandModel->customer_infos_optin_count }}</td>
|
||||
<td class="text-center align-middle bg-white">
|
||||
<span class="badge bg-warning text-dark text-wrap">{{ $brandModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }}</span>
|
||||
</td>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue