laravel雄辩的select()和get()之间的区别 [英] Difference between select() and get() in laravel eloquent

查看:986
本文介绍了laravel雄辩的select()和get()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用laravel雄辩的模型时,get()和select()方法之间是否有任何区别.哪种方法更快?

Is there any Difference between get() and select() method when using laravel eloquent model. Which method is faster?

推荐答案

是的. select()仅用于定义所需的列. get()用于实际获取结果(>执行查询),它还允许您指定列.

Yes there is a difference. select() is only for defining which columns you want. get() is for actually getting the result (> executing the query) and it also allows you to specify columns.

DB::table('foo')->select(array('bar'));

不执行.您仍然需要get()

DB::table('foo')->select(array('bar'))->get();

现在您只收到bar列的结果.
可以通过这种方式完成同样的操作:

Now you receive a result with only the bar column.
The same can be done this way:

DB::table('foo')->get(array('bar'));

所以单独按语法 get()更快(意味着更短),而就性能而言,您不会注意到任何区别.

So syntax-wise get() alone is faster (meaning shorter) while performance wise you won't notice any difference.

另一个小区别:通过select(),您可以使用列表语法

Another little difference: with select() you can use the list syntax

select('foo', 'bar', 'etc', 'whatever')

,并且使用get(),您必须使用数组

and with get() you have to use an array

get(array('foo', 'bar', 'etc', 'whatever'))

这篇关于laravel雄辩的select()和get()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆