Last active
August 29, 2015 13:57
-
-
Save appleboy/9433768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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