Skip to content

Instantly share code, notes, and snippets.

@MartelliEnrico
Last active August 29, 2015 14:10
Show Gist options
  • Save MartelliEnrico/282ff203c73283f2cf31 to your computer and use it in GitHub Desktop.
Save MartelliEnrico/282ff203c73283f2cf31 to your computer and use it in GitHub Desktop.
Model.php
<?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