Created
May 23, 2020 10:08
-
-
Save rakibdevs/9691ec0f43f5292f37e3c1837024c680 to your computer and use it in GitHub Desktop.
Laravel next and previous post
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
class Post extends Model | |
{ | |
……………………………………. | |
public function next() | |
{ | |
return $this->where(‘id’, ‘>’, $this->id)->orderBy(‘id’,’asc’)->first(); | |
} | |
public function previous() | |
{ | |
return $this->where(‘id’, ‘<’, $this->id)->orderBy(‘id’,’desc’)->first(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment