Home >Backend Development >PHP Tutorial >Laravel的Eloquent ORM 怎么获取当前记录的下一条

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

WBOY
WBOYOriginal
2016-06-06 20:31:071663browse

我想获取下一条把它的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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn