public function getNotifications(Request $request) { try { $session_token = $request->get('session_token'); $index = $request->get('index', 1); $limit = 10; $offset = $index - 1; $notifications = Notification::take($limit)->offset($offset * $limit)->orderBy('created_at', 'DESC')->get(); $data = []; $timeAgo = new TimeAgo(); foreach ($notifications as $notification) { $data[] = ['id' => $notification->id, 'subject' => $notification->subject, 'body' => $notification->body, 'ago' => $timeAgo->inWords($notification->created_at)]; } return Response::json(['status' => 1, 'message' => 'Success', 'data' => $data]); } catch (Exception $e) { return Response::json(['status' => 0, 'message' => $e->getMessage()]); } }