@@ -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') `
0 commit comments