From df7131aa7a3a536ff8b7af56a1e287b686ff7e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 10 Sep 2021 16:11:52 +0200 Subject: [PATCH] memorize customer filters on session --- app/Http/Controllers/CustomerController.php | 20 +++++++++++++------- resources/views/customer/index.blade.php | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 58b5299..0ca0a9f 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -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"); } diff --git a/resources/views/customer/index.blade.php b/resources/views/customer/index.blade.php index 0b73358..b700135 100644 --- a/resources/views/customer/index.blade.php +++ b/resources/views/customer/index.blade.php @@ -20,11 +20,11 @@ - + @if(request()->brand)