在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()之间的区别
发布评论