11
11
/**
12
12
* @template TModel of \Illuminate\Database\Eloquent\Model
13
13
* @extends Builder<TModel>
14
+ * @mixin \Illuminate\Database\Query\Builder
14
15
*/
15
16
class SpatialBuilder extends Builder
16
17
{
@@ -23,14 +24,16 @@ public function withDistance(
23
24
$ this ->select ('* ' );
24
25
}
25
26
26
- return $ this ->selectRaw (
27
+ $ this ->selectRaw (
27
28
sprintf (
28
29
'ST_DISTANCE(%s, %s) AS %s ' ,
29
30
"` {$ column }` " ,
30
31
$ this ->toExpression ($ geometryOrColumn ),
31
32
$ alias ,
32
33
)
33
34
);
35
+
36
+ return $ this ;
34
37
}
35
38
36
39
public function whereDistance (
@@ -39,7 +42,7 @@ public function whereDistance(
39
42
string $ operator ,
40
43
int |float $ value
41
44
): self {
42
- return $ this ->whereRaw (
45
+ $ this ->whereRaw (
43
46
sprintf (
44
47
'ST_DISTANCE(%s, %s) %s %s ' ,
45
48
"` {$ column }` " ,
@@ -48,21 +51,25 @@ public function whereDistance(
48
51
$ value ,
49
52
)
50
53
);
54
+
55
+ return $ this ;
51
56
}
52
57
53
58
public function orderByDistance (
54
59
string $ column ,
55
60
Geometry |string $ geometryOrColumn ,
56
61
string $ direction = 'asc '
57
62
): self {
58
- return $ this ->orderByRaw (
63
+ $ this ->orderByRaw (
59
64
sprintf (
60
65
'ST_DISTANCE(%s, %s) %s ' ,
61
66
"` {$ column }` " ,
62
67
$ this ->toExpression ($ geometryOrColumn ),
63
68
$ direction ,
64
69
)
65
70
);
71
+
72
+ return $ this ;
66
73
}
67
74
68
75
public function withDistanceSphere (
@@ -74,14 +81,16 @@ public function withDistanceSphere(
74
81
$ this ->select ('* ' );
75
82
}
76
83
77
- return $ this ->selectRaw (
84
+ $ this ->selectRaw (
78
85
sprintf (
79
86
'ST_DISTANCE_SPHERE(%s, %s) AS %s ' ,
80
87
"` {$ column }` " ,
81
88
$ this ->toExpression ($ geometryOrColumn ),
82
89
$ alias ,
83
90
)
84
91
);
92
+
93
+ return $ this ;
85
94
}
86
95
87
96
public function whereDistanceSphere (
@@ -90,7 +99,7 @@ public function whereDistanceSphere(
90
99
string $ operator ,
91
100
int |float $ value
92
101
): self {
93
- return $ this ->whereRaw (
102
+ $ this ->whereRaw (
94
103
sprintf (
95
104
'ST_DISTANCE_SPHERE(%s, %s) %s %s ' ,
96
105
"` {$ column }` " ,
@@ -99,109 +108,129 @@ public function whereDistanceSphere(
99
108
$ value
100
109
)
101
110
);
111
+
112
+ return $ this ;
102
113
}
103
114
104
115
public function orderByDistanceSphere (
105
116
string $ column ,
106
117
Geometry |string $ geometryOrColumn ,
107
118
string $ direction = 'asc '
108
119
): self {
109
- return $ this ->orderByRaw (
120
+ $ this ->orderByRaw (
110
121
sprintf (
111
122
'ST_DISTANCE_SPHERE(%s, %s) %s ' ,
112
123
"` {$ column }` " ,
113
124
$ this ->toExpression ($ geometryOrColumn ),
114
125
$ direction
115
126
)
116
127
);
128
+
129
+ return $ this ;
117
130
}
118
131
119
132
public function whereWithin (string $ column , Geometry |string $ geometryOrColumn ): self
120
133
{
121
- return $ this ->whereRaw (
134
+ $ this ->whereRaw (
122
135
sprintf (
123
136
'ST_WITHIN(%s, %s) ' ,
124
137
"` {$ column }` " ,
125
138
$ this ->toExpression ($ geometryOrColumn ),
126
139
)
127
140
);
141
+
142
+ return $ this ;
128
143
}
129
144
130
145
public function whereContains (string $ column , Geometry |string $ geometryOrColumn ): self
131
146
{
132
- return $ this ->whereRaw (
147
+ $ this ->whereRaw (
133
148
sprintf (
134
149
'ST_CONTAINS(%s, %s) ' ,
135
150
"` {$ column }` " ,
136
151
$ this ->toExpression ($ geometryOrColumn ),
137
152
)
138
153
);
154
+
155
+ return $ this ;
139
156
}
140
157
141
158
public function whereTouches (string $ column , Geometry |string $ geometryOrColumn ): self
142
159
{
143
- return $ this ->whereRaw (
160
+ $ this ->whereRaw (
144
161
sprintf (
145
162
'ST_TOUCHES(%s, %s) ' ,
146
163
"` {$ column }` " ,
147
164
$ this ->toExpression ($ geometryOrColumn ),
148
165
)
149
166
);
167
+
168
+ return $ this ;
150
169
}
151
170
152
171
public function whereIntersects (string $ column , Geometry |string $ geometryOrColumn ): self
153
172
{
154
- return $ this ->whereRaw (
173
+ $ this ->whereRaw (
155
174
sprintf (
156
175
'ST_INTERSECTS(%s, %s) ' ,
157
176
"` {$ column }` " ,
158
177
$ this ->toExpression ($ geometryOrColumn ),
159
178
)
160
179
);
180
+
181
+ return $ this ;
161
182
}
162
183
163
184
public function whereCrosses (string $ column , Geometry |string $ geometryOrColumn ): self
164
185
{
165
- return $ this ->whereRaw (
186
+ $ this ->whereRaw (
166
187
sprintf (
167
188
'ST_CROSSES(%s, %s) ' ,
168
189
"` {$ column }` " ,
169
190
$ this ->toExpression ($ geometryOrColumn ),
170
191
)
171
192
);
193
+
194
+ return $ this ;
172
195
}
173
196
174
197
public function whereDisjoint (string $ column , Geometry |string $ geometryOrColumn ): self
175
198
{
176
- return $ this ->whereRaw (
199
+ $ this ->whereRaw (
177
200
sprintf (
178
201
'ST_DISJOINT(%s, %s) ' ,
179
202
"` {$ column }` " ,
180
203
$ this ->toExpression ($ geometryOrColumn ),
181
204
)
182
205
);
206
+
207
+ return $ this ;
183
208
}
184
209
185
210
public function whereOverlaps (string $ column , Geometry |string $ geometryOrColumn ): self
186
211
{
187
- return $ this ->whereRaw (
212
+ $ this ->whereRaw (
188
213
sprintf (
189
214
'ST_OVERLAPS(%s, %s) ' ,
190
215
"` {$ column }` " ,
191
216
$ this ->toExpression ($ geometryOrColumn ),
192
217
)
193
218
);
219
+
220
+ return $ this ;
194
221
}
195
222
196
223
public function whereEquals (string $ column , Geometry |string $ geometryOrColumn ): self
197
224
{
198
- return $ this ->whereRaw (
225
+ $ this ->whereRaw (
199
226
sprintf (
200
227
'ST_EQUALS(%s, %s) ' ,
201
228
"` {$ column }` " ,
202
229
$ this ->toExpression ($ geometryOrColumn ),
203
230
)
204
231
);
232
+
233
+ return $ this ;
205
234
}
206
235
207
236
protected function toExpression (Geometry |string $ geometryOrColumn ): Expression
0 commit comments