66![ Lint] ( https://github.com/matanyadaev/laravel-eloquent-spatial/workflows/Lint/badge.svg )
77[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/matanyadaev/laravel-eloquent-spatial.svg?style=flat-square )] ( https://packagist.org/packages/matanyadaev/laravel-eloquent-spatial )
88
9- Laravel package to work with spatial data types and functions.
9+ ** This Laravel package allows you to easily work with spatial data types and functions.**
1010
11- The latest version (v3) supports Laravel 10 and PHP 8.1+. For Laravel 8 or 9, and PHP 8.0, use v2.
11+ The latest version, v3, supports Laravel 10 and PHP 8.1+. For Laravel 8 or 9, and PHP 8.0, use v2.
1212
1313This package supports MySQL v8, MySQL v5.7, and MariaDB v10.
1414
15- ## Installation
15+ ## Getting Started
16+
17+ ### Installing the Package
1618
1719You can install the package via composer:
1820
1921``` bash
2022composer require matanyadaev/laravel-eloquent-spatial
2123```
2224
23- ## Quickstart
24- Generate a new model with a migration file:
25- ``` bash
26- php artisan make:model {modelName} --migration
27- ```
25+ ### Setting Up Your First Model
2826
29- Add some spatial columns to the migration file:
27+ 1 . First, generate a new model along with a migration file by running :
3028
31- ``` php
32- use Illuminate\Database\Migrations\Migration;
33- use Illuminate\Database\Schema\Blueprint;
29+ ``` bash
30+ php artisan make:model {modelName} --migration
31+ ```
3432
35- class CreatePlacesTable extends Migration
36- {
37- public function up(): void
38- {
39- Schema::create('places', static function (Blueprint $table) {
40- $table->id();
41- $table->string('name')->unique();
42- $table->point('location')->nullable();
43- $table->polygon('area')->nullable();
44- $table->timestamps();
45- });
46- }
33+ 2 . Next, add some spatial columns to the migration file. For instance, to create a "places" table:
34+
35+ ``` php
36+ use Illuminate\Database\Migrations\Migration;
37+ use Illuminate\Database\Schema\Blueprint;
4738
48- public function down(): void
39+ class CreatePlacesTable extends Migration
4940 {
50- Schema::dropIfExists('places');
41+ public function up(): void
42+ {
43+ Schema::create('places', static function (Blueprint $table) {
44+ $table->id();
45+ $table->string('name')->unique();
46+ $table->point('location')->nullable();
47+ $table->polygon('area')->nullable();
48+ $table->timestamps();
49+ });
50+ }
51+
52+ public function down(): void
53+ {
54+ Schema::dropIfExists('places');
55+ }
5156 }
52- }
53- ```
57+ ```
5458
55- Run the migration:
59+ 3. Run the migration:
5660
57- ``` bash
58- php artisan migrate
59- ```
61+ ```bash
62+ php artisan migrate
63+ ```
6064
61- Fill the ` $fillable ` and ` $casts ` arrays and use the ` HasSpatial ` trait in your new model :
65+ 4. In your new model, fill the `$fillable` and `$casts` arrays and use the `HasSpatial` trait:
6266
63- ``` php
64- namespace App\Models;
67+ ```php
68+ namespace App\Models;
6569
66- use Illuminate\Database\Eloquent\Model;
67- use MatanYadaev\EloquentSpatial\SpatialBuilder;
68- use MatanYadaev\EloquentSpatial\Objects\Point;
69- use MatanYadaev\EloquentSpatial\Objects\Polygon;
70- use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
70+ use Illuminate\Database\Eloquent\Model;
71+ use MatanYadaev\EloquentSpatial\SpatialBuilder;
72+ use MatanYadaev\EloquentSpatial\Objects\Point;
73+ use MatanYadaev\EloquentSpatial\Objects\Polygon;
74+ use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
7175
72- /**
73- * @property Point $location
74- * @property Polygon $area
75- * @method static SpatialBuilder query()
76- */
77- class Place extends Model
78- {
79- use HasSpatial;
80-
81- protected $fillable = [
82- 'name',
83- 'location',
84- 'area',
85- ];
86-
87- protected $casts = [
88- 'location' => Point::class,
89- 'area' => Polygon::class,
90- ];
91- }
92- ```
76+ /**
77+ * @property Point $location
78+ * @property Polygon $area
79+ * @method static SpatialBuilder query()
80+ */
81+ class Place extends Model
82+ {
83+ use HasSpatial;
84+
85+ protected $fillable = [
86+ 'name',
87+ 'location',
88+ 'area',
89+ ];
90+
91+ protected $casts = [
92+ 'location' => Point::class,
93+ 'area' => Polygon::class,
94+ ];
95+ }
96+ ```
97+
98+ ### Interacting with Spatial Data
9399
94- Access spatial data:
100+ After setting up your model, you can now create and access spatial data. Here's an example :
95101
96102```php
97103use App\Models\Place;
@@ -140,13 +146,13 @@ echo $whiteHouse->location->srid; // 4326
140146echo $vacationCity->area->toJson(); // {"type":"Polygon","coordinates":[[[41.90746728266806,12.455363273620605],[41.906636872349075,12.450309991836548],[41.90197359839437,12.445632219314575],[41.90027269624499,12.447413206100464],[41.90000118654431,12.457906007766724],[41.90281205461268,12.458517551422117],[41.903107507989986,12.457584142684937],[41.905918239316286,12.457734346389769],[41.90637337450963,12.45572805404663],[41.90746728266806,12.455363273620605]]]}
141147```
142148
143- ## API
149+ ## Further Reading
144150
145- Please see [ API] ( API.md ) for more informative API documentation .
151+ For more comprehensive documentation on the API, please refer to the [ API] ( API.md ) page .
146152
147- ## Tip for better IDE support
153+ ## Tips for Improving IDE Support
148154
149- In order to get better IDE support, you should add a ` query ` method phpDoc annotation to your model:
155+ In order to get better IDE support, you can add a ` query ` method phpDoc annotation to your model:
150156
151157``` php
152158/**
@@ -158,7 +164,7 @@ class Place extends Model
158164}
159165```
160166
161- Or alternatively override the method:
167+ Or you could override the method:
162168
163169``` php
164170class Place extends Model
@@ -179,9 +185,9 @@ Place::whereDistance(...); // This is not
179185
180186## Extension
181187
182- You can extend the package by adding macro methods to the ` Geometry ` class.
188+ You can add new methods to the ` Geometry ` class through macros .
183189
184- Register a macro in the ` boot ` method of your service provider:
190+ Here's an example of how to register a macro in your service provider's ` boot ` method :
185191
186192``` php
187193class AppServiceProvider extends ServiceProvider
@@ -196,7 +202,7 @@ class AppServiceProvider extends ServiceProvider
196202}
197203```
198204
199- Use the macro in your code:
205+ Use the method in your code:
200206
201207``` php
202208$londonEyePoint = new Point(51.5032973, -0.1217424);
@@ -206,15 +212,17 @@ echo $londonEyePoint->getName(); // Point
206212
207213## Development
208214
209- * Test: ` composer pest `
210- * Test with coverage: ` composer pest-coverage `
211- * Type check: ` composer phpstan `
212- * Format: ` composer php-cs-fixer `
215+ Here are some useful commands for development:
216+
217+ * Run tests: ` composer pest `
218+ * Run tests with coverage: ` composer pest-coverage `
219+ * Perform type checking: ` composer phpstan `
220+ * Format your code: ` composer php-cs-fixer `
213221
214- ## Changelog
222+ ## Updates and Changes
215223
216- Please see [ CHANGELOG ] ( CHANGELOG.md ) for more information on what has changed recently .
224+ For details on updates and changes, please refer to our [ CHANGELOG ] ( CHANGELOG.md ) .
217225
218226## License
219227
220- The MIT License (MIT). Please see [ License File] ( LICENSE.md ) for more information .
228+ Laravel Eloquent Spatial is released under The MIT License (MIT). For more information, please see our [ License File] ( LICENSE.md ) .
0 commit comments