1
- # Laravel Eloquent Spatial
1
+ # Laravel Spatial
2
2
3
3
[ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/asanikovich/laravel-spatial.svg?style=flat-square )] ( https://packagist.org/packages/asanikovich/laravel-spatial )
4
- [ ![ GitHub Tests Action Status] ( https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/run-tests.yml?branch=main&label=tests&style=flat-square )] ( https://github.com/asanikovich/laravel-spatial/actions?query=workflow%3Arun-tests+branch%3Amain )
5
- [ ![ GitHub Code Style Action Status] ( https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square )] ( https://github.com/asanikovich/laravel-spatial/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain )
4
+ [ ![ GitHub Tests Status] ( https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/pest.yml?branch=master&label=tests&style=flat-square )] ( https://github.com/asanikovich/laravel-spatial/actions/workflows/pest.yml?query=branch%3Amaster )
5
+ [ ![ GitHub Tests Coverage Status] ( https://img.shields.io/codecov/c/github/asanikovich/laravel-spatial?token=E0703O0PPT&style=flat-square )] ( https://github.com/asanikovich/laravel-spatial/actions/workflows/pest-coverage.yml?query=branch%3Amaster )
6
+ [ ![ GitHub Code Style Status] ( https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/phpstan.yml?branch=master&label=code%20style&style=flat-square )] ( https://github.com/asanikovich/laravel-spatial/actions/workflows/phpstan.yml?query=branch%3Amaster )
7
+ [ ![ GitHub Lint Status] ( https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/pint.yml?branch=master&label=lint&style=flat-square )] ( https://github.com/asanikovich/laravel-spatial/actions/workflows/pint.yml?query=branch%3Amaster )
6
8
[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/asanikovich/laravel-spatial.svg?style=flat-square )] ( https://packagist.org/packages/asanikovich/laravel-spatial )
9
+ [ ![ Licence] ( https://img.shields.io/packagist/l/asanikovich/laravel-spatial.svg?style=flat-square )] ( https://packagist.org/packages/asanikovich/laravel-spatial )
7
10
8
11
** This Laravel package allows you to easily work with spatial data types and functions.**
9
12
10
- The latest version, v3, supports Laravel 10 and PHP 8.1+. For Laravel 8 or 9, and PHP 8.0, use v2 .
13
+ v1 supports Laravel 8,9 and PHP 8.1+ .
11
14
12
- This package supports MySQL v8, MySQL v5.7, and MariaDB v10.
15
+ This package supports MySQL v8 or v5.7, and MariaDB v10.
13
16
14
17
## Getting Started
15
18
@@ -21,12 +24,32 @@ You can install the package via composer:
21
24
composer require asanikovich/laravel-spatial
22
25
```
23
26
27
+ ### Configuration
28
+
29
+ Default Configuration file includes geometry types mapping:
30
+ ``` php
31
+ <?php
32
+
33
+ use ASanikovich\LaravelSpatial\Enums\GeometryType;
34
+ use ASanikovich\LaravelSpatial\Geometry;
35
+
36
+ return [
37
+ GeometryType::POINT->value => Geometry\Point::class,
38
+ GeometryType::POLYGON->value => Geometry\Polygon::class,
39
+ /// ...
40
+ ];
41
+ ```
42
+
24
43
You can publish the config file with:
25
44
26
45
``` bash
27
46
php artisan vendor:publish --tag=" laravel-spatial-config"
28
47
```
29
48
49
+ If you want you can override custom geometry types mapping:
50
+ * globally by config file
51
+ * by custom ` $casts ` in your model (top priority)
52
+
30
53
### Setting Up Your First Model
31
54
32
55
1 . First, generate a new model along with a migration file by running:
@@ -67,21 +90,19 @@ php artisan vendor:publish --tag="laravel-spatial-config"
67
90
php artisan migrate
68
91
```
69
92
70
- 4. In your new model, fill the `$fillable` and `$ casts` arrays and use the `HasSpatial` trait:
93
+ 4. In your new model, fill `$ casts` arrays and use the `HasSpatial` trait (fill the `$fillable` - optional) :
71
94
72
95
```php
73
96
namespace App\Models;
74
97
75
98
use Illuminate\Database\Eloquent\Model;
76
99
use ASanikovich\LaravelSpatial\Eloquent\HasSpatial;
77
- use ASanikovich\LaravelSpatial\Eloquent\SpatialBuilder;
78
100
use ASanikovich\LaravelSpatial\Geometry\Point;
79
101
use ASanikovich\LaravelSpatial\Geometry\Polygon;
80
102
81
103
/**
82
104
* @property Point $location
83
105
* @property Polygon $area
84
- * @method static SpatialBuilder<Place > query()
85
106
*/
86
107
class Place extends Model
87
108
{
@@ -155,25 +176,9 @@ echo $vacationCity->area->toJson(); // {"type":"Polygon","coordinates":[[[41.907
155
176
156
177
For more comprehensive documentation on the API, please refer to the [ API] ( API.md ) page.
157
178
158
- ## Tips for Improving IDE Support
159
-
160
- In order to get better IDE support, you can add a ` query ` method phpDoc annotation to your model:
161
-
162
- ``` php
163
- /**
164
- * @method static SpatialBuilder query()
165
- */
166
- class Place extends Model
167
- {
168
- // ...
169
- }
170
- ```
171
-
172
- Create queries only with the ` query() ` static method:
173
-
179
+ Create queries only with scopes methods:
174
180
``` php
175
- Place::query()->whereDistance(...); // This is IDE-friendly
176
- Place::whereDistance(...); // This is not
181
+ Place::whereDistance(...); // This is IDE-friendly
177
182
```
178
183
179
184
## Extension
@@ -204,18 +209,37 @@ echo $londonEyePoint->getName(); // Point
204
209
```
205
210
206
211
## Development
212
+ Here are some useful commands for development
207
213
208
- Here are some useful commands for development:
209
-
210
- * Run tests: ` composer pest `
211
- * Run tests with coverage: ` composer pest-coverage `
212
- * Perform type checking: ` composer phpstan `
213
- * Format your code: ` composer format `
214
+ Before running tests run db by docker-compose:
215
+ ``` bash
216
+ docker-compose up -d
217
+ ```
218
+ Run tests:
219
+ ``` bash
220
+ composer run test
221
+ ```
222
+ Run tests with coverage:
223
+ ``` bash
224
+ composer run test-coverage
225
+ ```
226
+ Perform type checking:
227
+ ``` bash
228
+ composer run phpstan
229
+ ```
230
+ Format your code:
231
+ ``` bash
232
+ composer run format
233
+ ```
214
234
215
235
## Updates and Changes
216
236
217
237
For details on updates and changes, please refer to our [ CHANGELOG] ( CHANGELOG.md ) .
218
238
219
239
## License
220
240
221
- Laravel Eloquent Spatial is released under The MIT License (MIT). For more information, please see our [ License File] ( LICENSE.md ) .
241
+ Laravel Spatial is released under The MIT License (MIT). For more information, please see our [ License File] ( LICENSE.md ) .
242
+
243
+ ## Credits
244
+
245
+ Originally inspired from [ MatanYadaev's laravel-eloquent-spatial package] ( https://github.com/MatanYadaev/laravel-eloquent-spatial ) .
0 commit comments