6
6
![ Lint] ( https://github.com/matanyadaev/laravel-eloquent-spatial/workflows/Lint/badge.svg )
7
7
[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/matanyadaev/laravel-eloquent-spatial.svg?style=flat-square )] ( https://packagist.org/packages/matanyadaev/laravel-eloquent-spatial )
8
8
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.**
10
10
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.
12
12
13
13
This package supports MySQL v8, MySQL v5.7, and MariaDB v10.
14
14
15
- ## Installation
15
+ ## Getting Started
16
+
17
+ ### Installing the Package
16
18
17
19
You can install the package via composer:
18
20
19
21
``` bash
20
22
composer require matanyadaev/laravel-eloquent-spatial
21
23
```
22
24
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
28
26
29
- Add some spatial columns to the migration file:
27
+ 1 . First, generate a new model along with a migration file by running :
30
28
31
- ``` php
32
- use Illuminate\Database\Migrations\Migration;
33
- use Illuminate\Database\Schema\Blueprint;
29
+ ``` bash
30
+ php artisan make:model {modelName} --migration
31
+ ```
34
32
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;
47
38
48
- public function down(): void
39
+ class CreatePlacesTable extends Migration
49
40
{
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
+ }
51
56
}
52
- }
53
- ```
57
+ ```
54
58
55
- Run the migration:
59
+ 3. Run the migration:
56
60
57
- ``` bash
58
- php artisan migrate
59
- ```
61
+ ```bash
62
+ php artisan migrate
63
+ ```
60
64
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:
62
66
63
- ``` php
64
- namespace App\Models;
67
+ ```php
68
+ namespace App\Models;
65
69
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;
71
75
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
93
99
94
- Access spatial data:
100
+ After setting up your model, you can now create and access spatial data. Here's an example :
95
101
96
102
```php
97
103
use App\Models\Place;
@@ -140,13 +146,13 @@ echo $whiteHouse->location->srid; // 4326
140
146
echo $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]]]}
141
147
```
142
148
143
- ## API
149
+ ## Further Reading
144
150
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 .
146
152
147
- ## Tip for better IDE support
153
+ ## Tips for Improving IDE Support
148
154
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:
150
156
151
157
``` php
152
158
/**
@@ -158,7 +164,7 @@ class Place extends Model
158
164
}
159
165
```
160
166
161
- Or alternatively override the method:
167
+ Or you could override the method:
162
168
163
169
``` php
164
170
class Place extends Model
@@ -179,9 +185,9 @@ Place::whereDistance(...); // This is not
179
185
180
186
## Extension
181
187
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 .
183
189
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 :
185
191
186
192
``` php
187
193
class AppServiceProvider extends ServiceProvider
@@ -196,7 +202,7 @@ class AppServiceProvider extends ServiceProvider
196
202
}
197
203
```
198
204
199
- Use the macro in your code:
205
+ Use the method in your code:
200
206
201
207
``` php
202
208
$londonEyePoint = new Point(51.5032973, -0.1217424);
@@ -206,15 +212,17 @@ echo $londonEyePoint->getName(); // Point
206
212
207
213
## Development
208
214
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 `
213
221
214
- ## Changelog
222
+ ## Updates and Changes
215
223
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 ) .
217
225
218
226
## License
219
227
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