Last active
August 29, 2015 14:10
-
-
Save MartelliEnrico/282ff203c73283f2cf31 to your computer and use it in GitHub Desktop.
Model.php
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 | |
use Illuminate\Database\Eloquent\Model as Eloquent; | |
class Model extends Eloquent { | |
public function scopeNext($query) | |
{ | |
$id = $this->getKeyName(); | |
$query = $this->newQuery(); | |
return $query->where($id, '<', $this->getAttribute($id))->max($id); | |
} | |
public function scopePrevious($query) | |
{ | |
$id = $this->getKeyName(); | |
$query = $this->newQuery(); | |
return $query->where($id, '>', $this->getAttribute($id))->min($id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment