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

编程入门 行业动态 更新时间:2024-10-27 12:32:37
本文介绍了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()之间的区别

本文发布于:2023-11-23 19:28:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   Eloquent   Model

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!