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:
5656php artisan migrate
5757```
5858
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:
6060
6161``` php
6262namespace App\Models;
@@ -65,6 +65,7 @@ use Illuminate\Database\Eloquent\Model;
6565use MatanYadaev\EloquentSpatial\SpatialBuilder;
6666use MatanYadaev\EloquentSpatial\Objects\Point;
6767use MatanYadaev\EloquentSpatial\Objects\Polygon;
68+ use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
6869
6970/**
7071 * @property Point $location
@@ -73,6 +74,8 @@ use MatanYadaev\EloquentSpatial\Objects\Polygon;
7374 */
7475class Place extends Model
7576{
77+ use HasSpatial;
78+
7679 protected $fillable = [
7780 'name',
7881 'location',
@@ -83,11 +86,6 @@ class Place extends Model
8386 'location' => Point::class,
8487 'area' => Polygon::class,
8588 ];
86-
87- public function newEloquentBuilder($query): SpatialBuilder
88- {
89- return new SpatialBuilder($query);
90- }
9189}
9290```
9391
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 1313use MatanYadaev \EloquentSpatial \Objects \Polygon ;
1414use MatanYadaev \EloquentSpatial \SpatialBuilder ;
1515use MatanYadaev \EloquentSpatial \Tests \TestFactories \TestPlaceFactory ;
16+ use MatanYadaev \EloquentSpatial \Traits \HasSpatial ;
1617
1718/**
1819 * @property Point $point
3031 */
3132class TestPlace extends Model
3233{
33- use HasFactory;
34+ use HasFactory, HasSpatial ;
3435
3536 protected $ fillable = [
3637 'address ' ,
@@ -55,16 +56,6 @@ class TestPlace extends Model
5556 'point_with_line_string_cast ' => LineString::class,
5657 ];
5758
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-
6859 protected static function newFactory (): TestPlaceFactory
6960 {
7061 return new TestPlaceFactory ;
You can’t perform that action at this time.
0 commit comments