使用 Laravel Eloquent ORM 实现 MySQL Spatial 函数


Implementing MySQL Spatial functions using Laravel Eloquent ORM

查询 1:

"从search_table WHERE 列中选择 *>=4">

"查询1"的雄辩ORM实现

$searchResults = SearchTempTable::select(*);
$searchResults = $searchResults->where('column', '>=', 4);

查询 2:

"从search_table位置选择 * ST_Intersects(column, geomfromtext( 'POLYGON(($point 1X $point 1Y, $point 2X $point 2Y, $point 3X $point 3Y,$point 4X $point 4Y,$point 1X $point 1Y(('((">

如何在 Eloquent ORM 中实现"查询 2"?

只有raw语句才能用于此。

$bindings = [$point1X, $point1Y, ... ];
SearchTempTable::whereRaw(
 "ST_Intersects(column, geomfromtext( 'POLYGON((? ?, ? ?, ? ?, ? ?, ? ?))' ))",
  $bindings
)->get();