简体   繁体   English

查询构建器加入原始(postgres / postgis)

[英]Query builder join raw (postgres / postgis)

Is it possible to do this query in Laravel query builder?是否可以在 Laravel 查询生成器中执行此查询?

SELECT table2.id FROM table1
JOIN table2 ON ST_Intersects(table2.geom,table1.geom)
WHERE table1.id = 1234

I have tried to search in Laravel doc (Advanced Join Clauses) but I couldn't find any example that fit my problem.我曾尝试在 Laravel 文档(高级连接子句)中进行搜索,但找不到任何适合我的问题的示例。

$query = Table1::query()
    ->select('table2.id')
    ->join(...)
    ->where('table1.id','=',1234)
    ->get();

Ok, I have found the solution:好的,我找到了解决方案:

$query = Table1::query()
    ->select('table2.id')
    ->join('table2', function ($query) {  
        $query->where(\DB::raw('ST_Intersects(table2.geom,table1.geom)'), true);
    })
    ->where('table1.id','=',1234)
    ->get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM