/** * * Return the Available tickets as Json Response * * @param get the pagination number * @return Json Response * */ private function loadTableAvailableTickets($skiper) { $lists = adminUserTickets::lists('ticketid'); $tickets = tickets::whereNotIn('id', $lists)->where('opened', 1)->skip($this->resultCount * $skiper)->take($this->resultCount)->get(); $count = tickets::whereNotIn('id', $lists)->where('opened', 1)->count(); $lastMessages = array(); for ($x = 0; $x < sizeof($tickets); $x++) { $ticketsMessages = tickets_messages::where('ticket_id', $tickets[$x]->id)->orderBy('id', 'desc')->first(); $lastMessages[] = $ticketsMessages; } return response()->json(['tickets' => $tickets, 'code' => 'success', 'task' => 'loadtableAvailabletickets', 'total' => $count, 'msgs' => $lastMessages, 'skips' => $this->resultCount]); }