Eloquent \ Model :: get()和all()之间的区别 [英] Difference between Eloquent\Model::get() and all()

查看:56
本文介绍了Eloquent \ Model :: get()和all()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eloquent上使用User::all()User::get()有什么区别?

What is the difference between uses User::all() and User::get() on Eloquent?

在Laravel API上,它仅描述 all() Eloquent\Model上.
也许 get() Eloquent\Builder中进行了说明.

On Laravel API it describes only all() on Eloquent\Model.
Maybe get() is described on Eloquent\Builder.

推荐答案

User::all()User::get()会做完全相同的事情.

User::all() and User::get() will do the exact same thing.

all()Eloquent\Model上的静态方法.它所做的只是创建一个新的查询对象并在其上调用get().使用all(),您根本无法修改执行的查询(除非您可以通过将其作为参数传递来选择要选择的列).

all() is a static method on the Eloquent\Model. All it does is create a new query object and call get() on it. With all(), you cannot modify the query performed at all (except you can choose the columns to select by passing them as parameters).

get()Eloquent\Builder对象上的方法.如果需要修改查询,例如添加where子句,则必须使用get().例如,User::where('name', 'David')->get();.

get() is a method on the Eloquent\Builder object. If you need to modify the query, such as adding a where clause, then you have to use get(). For example, User::where('name', 'David')->get();.

这篇关于Eloquent \ Model :: get()和all()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆