public function search() { //TODO Rate limit $query = Input::get('query'); $max = Input::has('size') && Input::get('size') < 61 ? Input::get('size') : 25; $last = Input::has('last') ? Input::get('last') : Post::orderBy('id', 'desc')->first()->id; $posts = Post::where('text', 'ilike', '%' . $query . '%')->where('id', '<', $last)->orderBy('id', 'desc')->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->take($max)->get(); return $this->respond($this->collectionTransformer->transformPosts($posts)); }
/** * Get all users posts * GET /api/users/self/posts * * @return Response */ public function selfPosts() { $user = Auth::user(); $max = 25; if (Input::has('size')) { $max = Input::get('size') > 61 ? $max : Input::get('size'); } if (Input::has('last')) { $posts = $user->posts()->where('id', '<', Input::get('last'))->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->orderBy('id', 'desc')->take($max)->get(); } else { $posts = $user->posts()->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->orderBy('id', 'desc')->take($max)->get(); } return $this->respond($this->collectionTransformer->transformPosts($posts)); }
/** * Feed */ public function feed() { // $header = Request::header('User-Agent'); // if ($header == 'yol 1.0.1') // return $this->respondWithCustomStatusCode('Update', 452, 452); $user = Auth::user(); $subscriptions = $user->subscriptions->map(function ($subscription) { return $subscription->id; }); if ($subscriptions->isEmpty()) { return $this->respondNotFound('forum.no-subscriptions'); } $max = Input::has('size') && Input::get('size') < 61 ? Input::get('size') : 25; if (Input::has('timestamp')) { $posts = Post::whereIn('category_id', $subscriptions->toArray())->where('updated_at', '>', Input::get('timestamp'))->take($max)->get(); } elseif (Input::has('last')) { $posts = Post::whereIn('category_id', $subscriptions->toArray())->where('id', '<', Input::get('last'))->orderBy('id', 'desc')->take($max)->get(); } else { $posts = Post::whereIn('category_id', $subscriptions->toArray())->orderBy('id', 'desc')->take($max)->get(); } $posts->reverse(); $posts->load('user', 'likes', 'comments', 'images', 'geos', 'cars', 'carsWithNumbers', 'cars.images', 'category'); return $this->respond($this->collectionTransformer->transformPosts($posts)); }
public function userPosts($id) { $user = User::find($id); if (!$user) { return $this->respondNotFound('User not found'); } $max = 25; if (Input::has('size')) { $max = Input::get('size') > 61 ? $max : Input::get('size'); } if (Input::has('last')) { $posts = $user->posts()->where('id', '<', Input::get('last'))->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->orderBy('id', 'desc')->take($max)->get(); } else { $posts = $user->posts()->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->orderBy('id', 'desc')->take($max)->get(); } $posts->reverse(); return $this->respond($this->collectionTransformer->transformPosts($posts)); }