Rumah >pembangunan bahagian belakang >tutorial php >Laravel的Eloquent ORM 怎么获取当前记录的下一条
我想获取下一条把它的active字段更改为yes,但是这样貌似获取不到
<code>$next_active = $ips->where("id", ">", $ips_get->id)->first(); $next_active->update(["active" => "yes"]); </code>
我想获取下一条把它的active字段更改为yes,但是这样貌似获取不到
<code>$next_active = $ips->where("id", ">", $ips_get->id)->first(); $next_active->update(["active" => "yes"]); </code>
可以直接戳链接:http://segmentfault.com/a/1190000003019456
楼主的问题基本可以这样解决:
<code>protected function getNextArticleId($current_id) { return Article::where('id', '>', $current_id)->min('id'); } </code>
然后
<code>Article::find($this->getNextArticleId($current_article->id))->update(...); </code>
至于Article
,请自行替换成你的Model,Happy Hacking。