From 4248963d92278fc1de1cd30e9c329eeb421642bc Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 17 Apr 2016 14:03:37 +0300 Subject: [PATCH] Check if is_primary is set when sorting contacts --- app/Ninja/Repositories/ClientRepository.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Ninja/Repositories/ClientRepository.php b/app/Ninja/Repositories/ClientRepository.php index 46f16d0676e7..d3f943a07001 100644 --- a/app/Ninja/Repositories/ClientRepository.php +++ b/app/Ninja/Repositories/ClientRepository.php @@ -100,8 +100,9 @@ class ClientRepository extends BaseRepository $contacts = isset($data['contact']) ? [$data['contact']] : $data['contacts']; $contactIds = []; + // If the primary is set ensure it's listed first usort($contacts, function ($left, $right) { - return $right['is_primary'] - $left['is_primary']; + return (isset($right['is_primary']) ? $right['is_primary'] : 0) - (isset($left['is_primary']) ? $left['is_primary'] : 0); }); foreach ($contacts as $contact) {