本文介绍了将原始查询转换为Laravel雄辩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将此原始查询转换为Laravel雄辩的方式:
How to convert this raw query to Laravel eloquent way:
select c.name as country from country c, address ad, city ci where
ad.id = 1 and city.id = ad.city_id and c.code = ci.country_code
推荐答案
我将修改 Andrey Lutscevich
口才很好的部分的答案
I will modify the answer from Andrey Lutscevich
eloquent part
Country::select('country.name as country')->has('city')
->whereHas('address', function ($query)
{
$query->where('id', 1);
})
->get();
WhereHas methods put "where" conditions on your has queries
WhereHas methods put "where" conditions on your has queries
这篇关于将原始查询转换为Laravel雄辩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!