Difference between EloquentModel::get() and all()(EloquentModel::get() 和 all() 的区别)
问题描述
在 Eloquent 上使用 User::all() 和 User::get() 有什么区别?
What is the difference between uses User::all() and User::get() on Eloquent?
在 Laravel API 上它只描述了 all() 在 EloquentModel 上.
也许 get() 在 EloquentBuilder 中有描述.
On Laravel API it describes only all() on EloquentModel.
Maybe get() is described on EloquentBuilder.
推荐答案
User::all() 和 User::get() 将做完全相同的事情.
User::all() and User::get() will do the exact same thing.
all() 是 EloquentModel 上的一个静态方法.它所做的只是创建一个新的查询对象并对其调用 get().使用 all(),您根本无法修改执行的查询(除非您可以通过将它们作为参数传递来选择要选择的列).
all() is a static method on the EloquentModel. 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() 是 EloquentBuilder 对象上的一个方法.如果需要修改查询,比如添加where子句,那么就必须使用get().例如,User::where('name', 'David')->get();.
get() is a method on the EloquentBuilder 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();.
这篇关于EloquentModel::get() 和 all() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EloquentModel::get() 和 all() 的区别
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
