public function after($number) { if (Input::has('key') == false) { return $this->response->errorUnauthorized(); } $ads = Ad::whereRaw('id > ' . $number)->orderBy('message_number', 'DESC')->paginate(50); // Pass this array (collection) into a resource, which will also have a "Transformer" // This "Transformer" can be a callback or a new instance of a Transformer object // We type hint for array, because each item in the $ads var is an array return $this->response->withPaginator($ads, new AdTransformer()); }
private function slug($slug) { $latestSlug = Ad::whereRaw("slug RLIKE '^" . $slug . "(-[0-9]*)?\$'")->latest('id')->pluck('slug'); if ($latestSlug) { $pieces = explode('-', $latestSlug); $number = end($pieces); $slug .= '-' . ($number + 1); } return $slug; }