更新时间:2023-12-04 11:22:58
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();
.