1111/**
1212 * @template TModel of \Illuminate\Database\Eloquent\Model
1313 * @extends Builder<TModel>
14+ * @mixin \Illuminate\Database\Query\Builder
1415 */
1516class SpatialBuilder extends Builder
1617{
@@ -23,14 +24,16 @@ public function withDistance(
2324 $ this ->select ('* ' );
2425 }
2526
26- return $ this ->selectRaw (
27+ $ this ->selectRaw (
2728 sprintf (
2829 'ST_DISTANCE(%s, %s) AS %s ' ,
2930 "` {$ column }` " ,
3031 $ this ->toExpression ($ geometryOrColumn ),
3132 $ alias ,
3233 )
3334 );
35+
36+ return $ this ;
3437 }
3538
3639 public function whereDistance (
@@ -39,7 +42,7 @@ public function whereDistance(
3942 string $ operator ,
4043 int |float $ value
4144 ): self {
42- return $ this ->whereRaw (
45+ $ this ->whereRaw (
4346 sprintf (
4447 'ST_DISTANCE(%s, %s) %s %s ' ,
4548 "` {$ column }` " ,
@@ -48,21 +51,25 @@ public function whereDistance(
4851 $ value ,
4952 )
5053 );
54+
55+ return $ this ;
5156 }
5257
5358 public function orderByDistance (
5459 string $ column ,
5560 Geometry |string $ geometryOrColumn ,
5661 string $ direction = 'asc '
5762 ): self {
58- return $ this ->orderByRaw (
63+ $ this ->orderByRaw (
5964 sprintf (
6065 'ST_DISTANCE(%s, %s) %s ' ,
6166 "` {$ column }` " ,
6267 $ this ->toExpression ($ geometryOrColumn ),
6368 $ direction ,
6469 )
6570 );
71+
72+ return $ this ;
6673 }
6774
6875 public function withDistanceSphere (
@@ -74,14 +81,16 @@ public function withDistanceSphere(
7481 $ this ->select ('* ' );
7582 }
7683
77- return $ this ->selectRaw (
84+ $ this ->selectRaw (
7885 sprintf (
7986 'ST_DISTANCE_SPHERE(%s, %s) AS %s ' ,
8087 "` {$ column }` " ,
8188 $ this ->toExpression ($ geometryOrColumn ),
8289 $ alias ,
8390 )
8491 );
92+
93+ return $ this ;
8594 }
8695
8796 public function whereDistanceSphere (
@@ -90,7 +99,7 @@ public function whereDistanceSphere(
9099 string $ operator ,
91100 int |float $ value
92101 ): self {
93- return $ this ->whereRaw (
102+ $ this ->whereRaw (
94103 sprintf (
95104 'ST_DISTANCE_SPHERE(%s, %s) %s %s ' ,
96105 "` {$ column }` " ,
@@ -99,109 +108,129 @@ public function whereDistanceSphere(
99108 $ value
100109 )
101110 );
111+
112+ return $ this ;
102113 }
103114
104115 public function orderByDistanceSphere (
105116 string $ column ,
106117 Geometry |string $ geometryOrColumn ,
107118 string $ direction = 'asc '
108119 ): self {
109- return $ this ->orderByRaw (
120+ $ this ->orderByRaw (
110121 sprintf (
111122 'ST_DISTANCE_SPHERE(%s, %s) %s ' ,
112123 "` {$ column }` " ,
113124 $ this ->toExpression ($ geometryOrColumn ),
114125 $ direction
115126 )
116127 );
128+
129+ return $ this ;
117130 }
118131
119132 public function whereWithin (string $ column , Geometry |string $ geometryOrColumn ): self
120133 {
121- return $ this ->whereRaw (
134+ $ this ->whereRaw (
122135 sprintf (
123136 'ST_WITHIN(%s, %s) ' ,
124137 "` {$ column }` " ,
125138 $ this ->toExpression ($ geometryOrColumn ),
126139 )
127140 );
141+
142+ return $ this ;
128143 }
129144
130145 public function whereContains (string $ column , Geometry |string $ geometryOrColumn ): self
131146 {
132- return $ this ->whereRaw (
147+ $ this ->whereRaw (
133148 sprintf (
134149 'ST_CONTAINS(%s, %s) ' ,
135150 "` {$ column }` " ,
136151 $ this ->toExpression ($ geometryOrColumn ),
137152 )
138153 );
154+
155+ return $ this ;
139156 }
140157
141158 public function whereTouches (string $ column , Geometry |string $ geometryOrColumn ): self
142159 {
143- return $ this ->whereRaw (
160+ $ this ->whereRaw (
144161 sprintf (
145162 'ST_TOUCHES(%s, %s) ' ,
146163 "` {$ column }` " ,
147164 $ this ->toExpression ($ geometryOrColumn ),
148165 )
149166 );
167+
168+ return $ this ;
150169 }
151170
152171 public function whereIntersects (string $ column , Geometry |string $ geometryOrColumn ): self
153172 {
154- return $ this ->whereRaw (
173+ $ this ->whereRaw (
155174 sprintf (
156175 'ST_INTERSECTS(%s, %s) ' ,
157176 "` {$ column }` " ,
158177 $ this ->toExpression ($ geometryOrColumn ),
159178 )
160179 );
180+
181+ return $ this ;
161182 }
162183
163184 public function whereCrosses (string $ column , Geometry |string $ geometryOrColumn ): self
164185 {
165- return $ this ->whereRaw (
186+ $ this ->whereRaw (
166187 sprintf (
167188 'ST_CROSSES(%s, %s) ' ,
168189 "` {$ column }` " ,
169190 $ this ->toExpression ($ geometryOrColumn ),
170191 )
171192 );
193+
194+ return $ this ;
172195 }
173196
174197 public function whereDisjoint (string $ column , Geometry |string $ geometryOrColumn ): self
175198 {
176- return $ this ->whereRaw (
199+ $ this ->whereRaw (
177200 sprintf (
178201 'ST_DISJOINT(%s, %s) ' ,
179202 "` {$ column }` " ,
180203 $ this ->toExpression ($ geometryOrColumn ),
181204 )
182205 );
206+
207+ return $ this ;
183208 }
184209
185210 public function whereOverlaps (string $ column , Geometry |string $ geometryOrColumn ): self
186211 {
187- return $ this ->whereRaw (
212+ $ this ->whereRaw (
188213 sprintf (
189214 'ST_OVERLAPS(%s, %s) ' ,
190215 "` {$ column }` " ,
191216 $ this ->toExpression ($ geometryOrColumn ),
192217 )
193218 );
219+
220+ return $ this ;
194221 }
195222
196223 public function whereEquals (string $ column , Geometry |string $ geometryOrColumn ): self
197224 {
198- return $ this ->whereRaw (
225+ $ this ->whereRaw (
199226 sprintf (
200227 'ST_EQUALS(%s, %s) ' ,
201228 "` {$ column }` " ,
202229 $ this ->toExpression ($ geometryOrColumn ),
203230 )
204231 );
232+
233+ return $ this ;
205234 }
206235
207236 protected function toExpression (Geometry |string $ geometryOrColumn ): Expression
0 commit comments