count() == 0) { $group = new ClientsGroup([ 'code' => '0', 'name' => 'Без группы', ]); $group->save(); } $countPerPage = 25; $offset = ($input['page'] - 1) * $countPerPage; if ($input['group_id'] == 0) { $group = ClientsGroup::where('code', '=', $input['group_id'])->first(); } else { $group = ClientsGroup::where('id', '=', $input['group_id'])->first(); } $clients = Client::where('group_id', '=', $group['code'])->skip($offset)->take($countPerPage)->get(); $total = Client::where('group_id', '=', $group['code'])->count(); if ($total == NULL) { return [ 'status' => 'success', 'clients' => array(), 'total' => 0, 'size' => $countPerPage, 'pages' => 1, 'currentGroup' => $group['id'], ]; } else { foreach ($clients as $client) { $phone = ClientsPhone::where('client_guid', '=', $client['user_code'])->first(); $email = ClientsEmail::where('client_guid', '=', $client['user_code'])->first(); $address = ClientsAddress::where('client_guid', '=', $client['user_code'])->first(); $barcode = ClientsBarcode::where('client_guid', '=', $client['user_code'])->first(); $group = ClientsGroup::where('code', '=', $client['group_id'])->first(); $out[] = array( 'id' => $client['id'], 'client_group' => $group['id'], 'name' => $client['name'], 'phone' => $phone['phone'], 'email' => $email['email'], 'address' => $address['address'], 'barcode' => $barcode['code_id'], ); } return [ 'status' => 'success', 'clients' => $out, 'total' => $total, 'size' => $countPerPage, 'pages' => ceil($total / $countPerPage), 'currentGroup' => $group['id'], ]; } } }