[英]In Laravel Eloquent, does Model::get() actually fetch the results?
Consider this line: 考虑这一行:
$nodes = Node::orderBy("id", "desc")->take(5)->get()
After the execution of the above line, was the Database queried (results were returned)? 执行完上述行后,是否查询了数据库(返回了结果)?
Yes, it was queried, and you should have the results in $nodes
. 是的,已经查询过了,结果应该放在
$nodes
。
The ->get()
on the end is what prompts the execution of the query. 最后的
->get()
会提示执行查询。 Up until that is called, you can continue adding conditions to your query. 在调用之前,您可以继续向查询中添加条件。 The Advanced Wheres section of the Laravel docs has some good examples
Laravel文档的Advanced Wheres部分提供了一些很好的示例
Note - If you want to have a look at what's going on, you can always use DB::getQueryLog()
注意-如果您想看看发生了什么,可以随时使用
DB::getQueryLog()
$queries = DB::getQueryLog();
Something (very quick and dirty) like this works in a View
: 这样的东西(非常快又脏)可以在
View
:
@foreach(DB::getQueryLog() as $query)
<pre> {{ print_r($query) }}</pre>
@endforeach
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.