From fe517c11636e7579411cca738ad5371b4eae64cb Mon Sep 17 00:00:00 2001 From: Mohammed Aladham Date: Sat, 10 Jun 2023 16:09:33 +0300 Subject: [PATCH] fix: sql error when selecting All pages --- app/Http/Controllers/ContactsController.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php index f5e830fa994..33f357c92e6 100644 --- a/app/Http/Controllers/ContactsController.php +++ b/app/Http/Controllers/ContactsController.php @@ -740,11 +740,18 @@ public function list(Request $request) $perPage = $request->has('perPage') ? $request->input('perPage') : config('monica.number_of_contacts_pagination'); // search contacts - $contacts = $contacts->search($request->input('search') ?? '', $accountId, 'is_starred', 'desc', $sort) - ->paginate($perPage); + $contacts = $contacts->search($request->input('search') ?? '', $accountId, 'is_starred', 'desc', $sort); + + if($perPage == -1){ + $total = $contacts->count(); + $contacts = $contacts->get(); + }else{ + $contacts = $contacts->paginate($perPage); + $total = $contacts->total(); + } return [ - 'totalRecords' => $contacts->total(), + 'totalRecords' => $total, 'contacts' => ContactResource::collection($contacts), ]; }