Nimmy Alice Mathew
Nimmy Alice Mathew

Reputation: 95

Implementing MySQL Spatial functions using Laravel Eloquent ORM

Query 1:

"SELECT * from search_table WHERE column>=4"

Eloquent ORM Implementation of 'Query1'

$searchResults = SearchTempTable::select(*);

$searchResults = $searchResults->where('column', '>=', 4);

Query 2:

"SELECT * FROM search_table WHERE ST_Intersects(column, geomfromtext( 'POLYGON(($point1X $point1Y, $point2X $point2Y, $point3X $point3Y,$point4X $point4Y,$point1X $point1Y))'))"

How can 'Query 2' be implemented in Eloquent ORM?

Upvotes: 3

Views: 803

Answers (1)

Jarek Tkaczyk
Jarek Tkaczyk

Reputation: 81177

Only raw statement will work for this.

$bindings = [$point1X, $point1Y, ... ];

SearchTempTable::whereRaw(
 "ST_Intersects(column, geomfromtext( 'POLYGON((? ?, ? ?, ? ?, ? ?, ? ?))' ))",
  $bindings
)->get();

Upvotes: 4

Related Questions