11<?php
2- namespace Grimzy \LaravelSpatial \Eloquent ;
32
4- use Grimzy \LaravelSpatial \Exceptions \SpatialFieldsNotDefinedException ;
5- use Grimzy \LaravelSpatial \Types \Geometry ;
6- use Grimzy \LaravelSpatial \Types \GeometryInterface ;
7- use Grimzy \LaravelSpatial \Types \Point ;
3+ namespace Grimzy \LaravelMysqlSpatial \Eloquent ;
4+
5+ use Grimzy \LaravelMysqlSpatial \Exceptions \SpatialFieldsNotDefinedException ;
6+ use Grimzy \LaravelMysqlSpatial \Types \Geometry ;
7+ use Grimzy \LaravelMysqlSpatial \Types \GeometryInterface ;
88use Illuminate \Database \Eloquent \Builder as EloquentBuilder ;
99
1010trait SpatialTrait
@@ -25,7 +25,7 @@ trait SpatialTrait
2525 *
2626 * @param \Illuminate\Database\Query\Builder $query
2727 *
28- * @return \Grimzy\LaravelSpatial \Eloquent\Builder
28+ * @return \Grimzy\LaravelMysqlSpatial \Eloquent\Builder
2929 */
3030 public function newEloquentBuilder ($ query )
3131 {
@@ -68,47 +68,54 @@ public function getSpatialFields()
6868 if (property_exists ($ this , 'spatialFields ' )) {
6969 return $ this ->spatialFields ;
7070 } else {
71- throw new SpatialFieldsNotDefinedException (__CLASS__ . ' has to define $spatialFields ' );
71+ throw new SpatialFieldsNotDefinedException (__CLASS__ . ' has to define $spatialFields ' );
7272 }
7373 }
7474
75- public function scopeDistance ($ query , $ distance , $ geometry , $ column_name , $ exclude_self = false ) {
75+ public function scopeDistance ($ query , $ distance , $ geometry , $ column_name , $ exclude_self = false )
76+ {
7677 $ query ->whereRaw ("st_distance(` {$ column_name }`, GeomFromText(' {$ geometry ->toWkt ()}')) <= {$ distance }" );
7778
78- if ($ exclude_self ) {
79+ if ($ exclude_self ) {
7980 $ query ->whereRaw ("st_distance(` {$ column_name }`, GeomFromText(' {$ geometry ->toWkt ()}')) != 0 " );
8081 }
82+
8183 return $ query ;
8284 }
8385
84- public function scopeDistanceSphere ($ query , $ distance , $ geometry , $ column_name , $ exclude_self = false ) {
86+ public function scopeDistanceSphere ($ query , $ distance , $ geometry , $ column_name , $ exclude_self = false )
87+ {
8588 $ query ->whereRaw ("st_distance_sphere(` {$ column_name }`, GeomFromText(' {$ geometry ->toWkt ()}')) <= {$ distance }" );
8689
87- if ($ exclude_self ) {
90+ if ($ exclude_self ) {
8891 $ query ->whereRaw ("st_distance_sphere(` {$ column_name }`, GeomFromText(' {$ geometry ->toWkt ()}')) != 0 " );
8992 }
93+
9094 return $ query ;
9195 }
9296
93- public function scopeDistanceValue ($ query , $ geometry , $ column_name ) {
97+ public function scopeDistanceValue ($ query , $ geometry , $ column_name )
98+ {
9499 $ columns = $ query ->getQuery ()->columns ;
95100
96- if (! $ columns ) {
101+ if (! $ columns ) {
97102 $ query ->select ('* ' );
98103 }
99104 $ query ->selectRaw ("st_distance(` {$ column_name }`, GeomFromText(' {$ geometry ->toWkt ()}')) as distance " );
100105 }
101106
102- public function scopeDistanceSphereValue ($ query , $ geometry , $ column_name ) {
107+ public function scopeDistanceSphereValue ($ query , $ geometry , $ column_name )
108+ {
103109 $ columns = $ query ->getQuery ()->columns ;
104110
105- if (! $ columns ) {
111+ if (! $ columns ) {
106112 $ query ->select ('* ' );
107113 }
108114 $ query ->selectRaw ("st_distance_sphere(` {$ column_name }`, GeomFromText(' {$ geometry ->toWkt ()}')) as distance " );
109115 }
110116
111- public function scopeBounding ($ query , Geometry $ bounds , $ column_name ) {
117+ public function scopeBounding ($ query , Geometry $ bounds , $ column_name )
118+ {
112119 return $ query ->whereRaw ("st_intersects(GeomFromText(' {$ bounds ->toWkt ()}'), ` {$ column_name }`) " );
113120 }
114121}
0 commit comments