diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php index d2bc8215a7d..b3f455c63fc 100644 --- a/app/Http/Controllers/ContactsController.php +++ b/app/Http/Controllers/ContactsController.php @@ -744,11 +744,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), ]; }