Skip to content

Instantly share code, notes, and snippets.

@appleboy
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appleboy/9433768 to your computer and use it in GitHub Desktop.
Save appleboy/9433768 to your computer and use it in GitHub Desktop.
<?php
class MotelController extends \BaseController
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$offset = Input::get('offset', null);
$limit = Input::get('limit', null);
$items = Motel::ofLimit($limit)
->ofOffset($offset)
->get();
}
<?php
class Motel extends Eloquent
{
public function scopeOfLimit($query, $limit = null)
{
if (empty($limit)) {
return $query;
}
return $query->take(intval($limit));
}
public function scopeOfOffset($query, $offset = null)
{
if (empty($offset)) {
return $query;
}
return $query->skip(intval($offset));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment