From ce874ae5b291d998f43814a6ae0cc8f4131e8c77 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 8 Nov 2018 21:00:56 +0800 Subject: [PATCH] Refactor CustomerController@index method --- app/Http/Controllers/Partners/CustomersController.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Partners/CustomersController.php b/app/Http/Controllers/Partners/CustomersController.php index 0d37725..cb8d970 100644 --- a/app/Http/Controllers/Partners/CustomersController.php +++ b/app/Http/Controllers/Partners/CustomersController.php @@ -17,12 +17,9 @@ class CustomersController extends Controller */ public function index() { - $customers = Customer::where(function ($query) { - $query->where('name', 'like', '%'.request('q').'%'); - }) - ->latest() - ->withCount('projects') - ->paginate(25); + $customerQuery = Customer::latest()->withCount('projects'); + $customerQuery->where('name', 'like', '%'.request('q').'%'); + $customers = $customerQuery->paginate(25); return view('customers.index', compact('customers')); }