如何在Laravel中使用USING postgre JOIN?

时间:2017-12-13 10:28:51

标签: php postgresql laravel

我在下面有一个原始的postgresql查询:

SELECT DISTINCT ON (c.id)
a.first_name as name, b.slug as slug, b.name as property_name, 
d.building_area as building_area, e.address as address

FROM   developers c
JOIN properties b USING (id)
JOIN users a USING (id)
JOIN forms f USING (id)
JOIN property_types d USING (id)
JOIN property_items e USING (id)
WHERE b.developer_id = ".$developer['id']."
AND b.created_at >= '01-01-2017' AND b.created_at <= '01-01-2018'
ORDER  BY c.id, b.name, a.id, a.first_name
LIMIT 5

如何将其更改为Laravel eloquent?我想在执行查询后使用mutator函数来更改响应数据。

我试过这样的话:

$z = Developer::select(DB::raw('
DISTINCT ON (c.id)
a.first_name as name, b.slug as slug, b.name as property_name, 
d.building_area as building_area, e.address as address
            '))
->join(DB::raw('JOIN properties b USING (id)'))
->join(DB::raw('JOIN users a USING (id)'))
->join(DB::raw('JOIN forms f USING (id)'))
->join(DB::raw('JOIN property_types d USING (id)'))
->join(DB::raw('JOIN property_items e USING (id)'))
->get();
但是拉拉维尔说:

  

缺少Illuminate \ Database \ Query \ Builder :: join(),

的参数2

有什么想法吗?

任何帮助将不胜感激:D

谢谢

0 个答案:

没有答案