File tree Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Grimzy \LaravelMysqlSpatial \Eloquent ;
4+
5+ use \Illuminate \Database \Query \Builder ;
6+
7+ class BaseBuilder extends Builder
8+ {
9+ /**
10+ * Remove all of the expressions from a list of bindings.
11+ *
12+ * @param array $bindings
13+ * @return array
14+ */
15+ protected function cleanBindings (array $ bindings )
16+ {
17+ $ bindings = array_map (function ($ binding ) {
18+ return $ binding instanceof SpatialExpression ? $ binding ->getSpatialValue () : $ binding ;
19+ }, $ bindings );
20+
21+ return parent ::cleanBindings ($ bindings );
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -20,6 +20,6 @@ public function update(array $values)
2020
2121 protected function asWKT (GeometryInterface $ geometry )
2222 {
23- return $ this -> getQuery ()-> raw ( " ST_GeomFromText(' " . $ geometry-> toWKT (). " ') " );
23+ return new SpatialExpression ( $ geometry );
2424 }
2525}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Grimzy \LaravelMysqlSpatial \Eloquent ;
4+
5+ use Illuminate \Database \Query \Expression ;
6+
7+ class SpatialExpression extends Expression
8+ {
9+ public function getValue ()
10+ {
11+ return 'ST_GeomFromText(?) ' ;
12+ }
13+
14+ public function getSpatialValue ()
15+ {
16+ return $ this ->value ->toWkt ();
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -61,12 +61,21 @@ public function newEloquentBuilder($query)
6161 return new Builder ($ query );
6262 }
6363
64+ protected function newBaseQueryBuilder ()
65+ {
66+ $ connection = $ this ->getConnection ();
67+
68+ return new BaseBuilder (
69+ $ connection , $ connection ->getQueryGrammar (), $ connection ->getPostProcessor ()
70+ );
71+ }
72+
6473 protected function performInsert (EloquentBuilder $ query , array $ options = [])
6574 {
6675 foreach ($ this ->attributes as $ key => $ value ) {
6776 if ($ value instanceof GeometryInterface) {
6877 $ this ->geometries [$ key ] = $ value ; //Preserve the geometry objects prior to the insert
69- $ this ->attributes [$ key ] = $ this -> getConnection ()-> raw ( sprintf ( " ST_GeomFromText('%s') " , $ value-> toWKT ()) );
78+ $ this ->attributes [$ key ] = new SpatialExpression ( $ value );
7079 }
7180 }
7281
You can’t perform that action at this time.
0 commit comments