仅在模板里面不太好处理,需要调整一下问题详情的控制器,加入上一篇,下一篇的问题变量,然后模板里面调用即可,参考代码如下:
$preQuestion = Question::where("status","=",1)->where("id","<",$question->id)->orderBy("id","desc")->first(); //上一个问题
$nextQuestion = Question::where("status","=",1)->where("id",">",$question->id)->orderBy("id","asc")->first(); //下一个问题