public function privateMessages() { $since = intval(Request::input('since')); $limit = min(50, intval(Request::input('limit', 50))); $messages = PrivateMessage::toOrFrom($this->current_user->user_id)->with('sender')->with('receiver'); if ($since) { $messages = $messages->where('message_id', '>', $since); } $collection = json_collection($messages->orderBy('message_id', $since ? 'asc' : 'desc')->limit($limit)->get(), new PrivateMessageTransformer()); return $since ? $collection : array_reverse($collection); }