Today I saw an article in laravel that takes the code from the previous article and the next article. I feel good about it, so I would like to share it with you!
public function show($id){
//Get the current article
$current = Test::find($id);
//Get the previous article ID
$previousID = Test::where('id', '<', $id)->max('id');
//Similarly, get the next article ID
$nextId = Test::where('id', '>', $id)->min('id');
return view('art.show', compact ('current', 'previousID', 'nextId'));}
The same as other frameworks, get all the articles smaller than the current id and the one with the largest id is the previous article, and vice versa~~ So much to share! ! Thanks to the webmaster for providing the platform~
Is this very real? Sometimes thinking is important, right?