我是laravel的新手所以任何人都可以解释一下,雄辩的ORM究竟是什么样的get()函数呢。我有以下查询,我需要知道查询数据库的哪一行。
$propertiesQuery = Property::with('country', 'city','bannerInvoicesCount','rejectedBannerInvoicesCount')
->where('is_deleted','=',1);
if(Auth::user()->type == 'po') {
$propertiesQuery->where('user_id', '=', Auth::user()->id);
}
$propertiesQuery->orderBy('created_at', 'DESC');
$properties = $propertiesQuery->get();
现在在上面的代码中,我已经访问过Model,无论是查询db还是调用get()函数。我无法理解这方面的内部工作。那就是查询执行的语句。
答案 0 :(得分:2)
select * from table where user_id=1
当您调用/触发$ propertiesQuery-> get()方法时,它会将您的查询转发到数据库并根据您的查询获取记录。比如,通常我们在普通的sql中做:
eg: mysql_query($query);
then mysql_fetch_assoc() etc methods
所以get()方法包含on:执行查询并返回数组格式的所有记录。
我希望它会对你有所帮助。