File tree Expand file tree Collapse file tree 3 files changed +19
-17
lines changed Expand file tree Collapse file tree 3 files changed +19
-17
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ Run the migration:
56
56
php artisan migrate
57
57
```
58
58
59
- Fill the ` $fillable ` and ` $casts ` arrays and add custom eloquent builder to your new model:
59
+ Fill the ` $fillable ` and ` $casts ` arrays and use the ` HasSpatial ` trait in your new model:
60
60
61
61
``` php
62
62
namespace App\Models;
@@ -65,6 +65,7 @@ use Illuminate\Database\Eloquent\Model;
65
65
use MatanYadaev\EloquentSpatial\SpatialBuilder;
66
66
use MatanYadaev\EloquentSpatial\Objects\Point;
67
67
use MatanYadaev\EloquentSpatial\Objects\Polygon;
68
+ use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
68
69
69
70
/**
70
71
* @property Point $location
@@ -73,6 +74,8 @@ use MatanYadaev\EloquentSpatial\Objects\Polygon;
73
74
*/
74
75
class Place extends Model
75
76
{
77
+ use HasSpatial;
78
+
76
79
protected $fillable = [
77
80
'name',
78
81
'location',
@@ -83,11 +86,6 @@ class Place extends Model
83
86
'location' => Point::class,
84
87
'area' => Polygon::class,
85
88
];
86
-
87
- public function newEloquentBuilder($query): SpatialBuilder
88
- {
89
- return new SpatialBuilder($query);
90
- }
91
89
}
92
90
```
93
91
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace MatanYadaev \EloquentSpatial \Traits ;
4
+
5
+ use MatanYadaev \EloquentSpatial \SpatialBuilder ;
6
+
7
+ trait HasSpatial
8
+ {
9
+ public function newEloquentBuilder ($ query ): SpatialBuilder
10
+ {
11
+ return new SpatialBuilder ($ query );
12
+ }
13
+ }
Original file line number Diff line number Diff line change 13
13
use MatanYadaev \EloquentSpatial \Objects \Polygon ;
14
14
use MatanYadaev \EloquentSpatial \SpatialBuilder ;
15
15
use MatanYadaev \EloquentSpatial \Tests \TestFactories \TestPlaceFactory ;
16
+ use MatanYadaev \EloquentSpatial \Traits \HasSpatial ;
16
17
17
18
/**
18
19
* @property Point $point
30
31
*/
31
32
class TestPlace extends Model
32
33
{
33
- use HasFactory;
34
+ use HasFactory, HasSpatial ;
34
35
35
36
protected $ fillable = [
36
37
'address ' ,
@@ -55,16 +56,6 @@ class TestPlace extends Model
55
56
'point_with_line_string_cast ' => LineString::class,
56
57
];
57
58
58
- /**
59
- * @param $query
60
- * @return SpatialBuilder<TestPlace>
61
- */
62
- public function newEloquentBuilder ($ query ): SpatialBuilder
63
- {
64
- // @phpstan-ignore-next-line
65
- return new SpatialBuilder ($ query );
66
- }
67
-
68
59
protected static function newFactory (): TestPlaceFactory
69
60
{
70
61
return new TestPlaceFactory ;
You can’t perform that action at this time.
0 commit comments