Share a little trick about the previous article and the next one. Most people don't tell him!
冲
2018-10-17 22:39:16
0
0
907

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?

冲

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template