<p>laravel关于上一篇下一篇</p><p>上一篇下一篇的实质就是获取本条记录的上下两个id,通过sql语句实现如下:</p><p>上一篇:select id,title where id < id order by id desc limit(1);</p><p>下一篇:select`id`,`title` where `id` > id order by `id` asc limit 1</p><p>而在laravel Eloquent 中实现方法如下:</p><pre class="brush:php;toolbar:false">$prev=Blog::Active()->where('id','<',$id)->orderByDesc('id')->first();
$next=Blog::Active()->where('id','>',$id)->orderBy('id','asc')->first();</pre><p>如果只是想获取文章的id 直接通过Laravel中max方法来实现</p><pre class="brush:php;toolbar:false">$prev_id=Blog::Active()->where('id','<',$id)->max('id');
$next_id=Blog::Active()->where('id','>',$id)->min('id');</pre>