memorize customer filters on session

This commit is contained in:
Jérémy Munsch 2021-09-10 16:11:52 +02:00
parent 34e6a42f8d
commit df7131aa7a
2 changed files with 15 additions and 9 deletions

View file

@ -39,18 +39,22 @@ class CustomerController extends Controller
->join('brands', function (JoinClause $join) {
$join->on('brands.id', '=', 'customer_infos.brand_id');
});
if (request()->brand) {
$query = $query->where('customer_infos.brand_id', $request->brand);
if (request()->brand or Session::has("crud.$modelTable.brand")) {
$brand = $request->brand ?? Session::get("crud.$modelTable.brand");
Session::put("crud.$modelTable.brand", $brand);
$query = $query->where('customer_infos.brand_id', $brand);
}
// Search on crud Label column
if ($request->search) {
$query->where(function ($q) use ($columns, $request) {
if ($request->search or Session::has("crud.$modelTable.search")) {
$search = $request->search ?? Session::get("crud.$modelTable.search");
Session::put("crud.$modelTable.search", $search);
$query->where(function ($q) use ($columns, $search) {
foreach ($columns as $column) {
$q = $q->orWhere($column, 'LIKE', "%$request->search%");
$q = $q->orWhere($column, 'LIKE', "%$search%");
}
$q = $q->orWhere('customers.email', 'LIKE', "%$request->search%");
$q = $q->orWhere('customer_logins.last_connection', 'LIKE', "%$request->search%");
$q = $q->orWhere('customers.email', 'LIKE', "%$search%");
$q = $q->orWhere('customer_logins.last_connection', 'LIKE', "%$search%");
});
}
@ -63,6 +67,8 @@ class CustomerController extends Controller
}
if ($request->rst) {
Session::remove("crud.$modelTable.brand");
Session::remove("crud.$modelTable.search");
Session::remove("crud.$modelTable.sort_way");
Session::remove("crud.$modelTable.sort_col");
}

View file

@ -20,11 +20,11 @@
<select class="form-select" id="brandSelect">
<option value="0" @if(!request()->brand) selected @endif>{{ __('Sélectionnez une marque..') }}</option>
@foreach(Brand::all() as $brand)
<option value="{{ $brand->id }}" @if(request()->brand == "$brand->id") selected @endif>{{ $brand->name }}</option>
<option value="{{ $brand->id }}" @if(request()->brand == "$brand->id" or Session::get("crud.$modelTable.brand") == $brand->id) selected @endif>{{ $brand->name }}</option>
@endforeach
</select>
<label class="input-group-text bg-warning" for="searchField">🔍🠚</label>
<input type="search" id="searchField" name="search" class="form-control" value="{{ request()->search }}" placeholder="Recherche.."/>
<input type="search" id="searchField" name="search" class="form-control" value="{{ request()->search ?? Session::get("crud.$modelTable.search") }}" placeholder="Recherche.."/>
<input type="text" name="sort_col" class="d-none" value="{{ request()->sort_col }}"/>
<input type="text" name="sort_way" class="d-none" value="{{ request()->sort_way }}"/>
@if(request()->brand)