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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:31:07
Original
1703 people have browsed it

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

<code>$next_active = $ips->where("id", ">", $ips_get->id)->first();
$next_active->update(["active" => "yes"]);
</code>
Copy after login
Copy after login

回复内容:

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

<code>$next_active = $ips->where("id", ">", $ips_get->id)->first();
$next_active->update(["active" => "yes"]);
</code>
Copy after login
Copy after login

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

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

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

    }

</code>
Copy after login

然后

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

</code>
Copy after login

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

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template