且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eloquent \ Model :: get()和all()之间的区别

更新时间: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();.