Laravel的Eloquent ORM 怎么获取当前记录的下一条

我想获取下一条把它的active字段更改为yes,但是这样貌似获取不到

$next_active = $ips->where("id", ">", $ips_get->id)->first();
$next_active->update(["active" => "yes"]);
阅读 7.7k
1 个回答

可以直接戳链接:http://segmentfault.com/a/1190000003019456

楼主的问题基本可以这样解决:

protected function getNextArticleId($current_id)
    {
        return Article::where('id', '>', $current_id)->min('id');

    }

然后

Article::find($this->getNextArticleId($current_article->id))->update(...);

至于Article,请自行替换成你的Model,Happy Hacking

推荐问题
宣传栏