Skip to content

Commit 8b339d1

Browse files
committed
wip docs
1 parent f899fcd commit 8b339d1

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

API.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,63 @@ Geometry collection functions:
2727

2828
## Available spatial scopes
2929

30-
* `withDistance(string $column, Geometry | string $geometryOrColumn, string $alias = 'distance')`
30+
### withDistance
31+
32+
Retrieves the distance between 2 geometry objects.
33+
34+
| parameter name | type | default |
35+
| ------------------ | -------------------- | ------- |
36+
| `$column` | `string` |
37+
| `$geometryOrColumn` | `Geometry \| string` |
38+
| `$alias` | `string` | `'distance'`
39+
40+
<details><summary>Example</summary>
41+
42+
```php
43+
Place::create(['point' => new Point(0, 0)]);
44+
45+
$placeWithDistance = Place::query()
46+
->withDistance('point', new Point(1, 1))
47+
->first();
48+
49+
echo $placeWithDistance->distance; // 1.4142135623731
50+
51+
// when using alias:
52+
$placeWithDistance = Place::query()
53+
->withDistance('point', new Point(1, 1), 'distance_in_meters')
54+
->first();
55+
56+
echo $placeWithDistance->distance_in_meters; // 1.4142135623731
57+
```
58+
</details>
59+
60+
### whereDistance
61+
62+
Description
63+
64+
| parameter name | type
65+
| ------------------ | --------------------
66+
| `$column` | `string`
67+
| `$geometryOrColumn` | `Geometry \| string`
68+
| `$operator` | `string`
69+
| `$value` | `int \| float`
70+
71+
<details><summary>Example</summary>
72+
73+
```php
74+
Place::create([
75+
'name' => 'My place',
76+
'point' => new Point(0, 0),
77+
]);
78+
79+
$place = Place::query()
80+
->whereDistance('point', new Point(1, 1), '<', 10)
81+
->first();
82+
83+
echo $place->name; // My place
84+
```
85+
</details>
86+
3187
* `whereDistance(string $column, Geometry | string $geometryOrColumn, string $operator, int | float $distance)`
3288
* `orderByDistance(string $column, Geometry | string $geometryOrColumn, string $direction = 'asc')`
3389
* `withDistanceSphere(string $column, Geometry | string $geometryOrColumn, string $alias = 'distance')`

src/SpatialBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function whereDistance(
3535
string $column,
3636
Geometry | string $geometryOrColumn,
3737
string $operator,
38-
int | float $distance
38+
int | float $value
3939
): self {
4040
$geometryOrColumn = $this->toExpression($geometryOrColumn);
4141

@@ -45,7 +45,7 @@ public function whereDistance(
4545
"`{$column}`",
4646
$geometryOrColumn,
4747
$operator,
48-
$distance,
48+
$value,
4949
)
5050
);
5151
}
@@ -92,7 +92,7 @@ public function whereDistanceSphere(
9292
string $column,
9393
Geometry | string $geometryOrColumn,
9494
string $operator,
95-
int | float $distance
95+
int | float $value
9696
): self {
9797
$geometryOrColumn = $this->toExpression($geometryOrColumn);
9898

@@ -102,7 +102,7 @@ public function whereDistanceSphere(
102102
"`{$column}`",
103103
$geometryOrColumn,
104104
$operator,
105-
$distance
105+
$value
106106
)
107107
);
108108
}

0 commit comments

Comments
 (0)