diff --git a/README.md b/README.md index 96996ed..c8f77fb 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Run the migration: php artisan migrate ``` -Fill the `$fillable` and `$casts` arrays and add custom eloquent builder to your new model: +Fill the `$fillable` and `$casts` arrays and use the `HasSpatial` trait in your new model: ```php namespace App\Models; @@ -65,6 +65,7 @@ use Illuminate\Database\Eloquent\Model; use MatanYadaev\EloquentSpatial\SpatialBuilder; use MatanYadaev\EloquentSpatial\Objects\Point; use MatanYadaev\EloquentSpatial\Objects\Polygon; +use MatanYadaev\EloquentSpatial\Traits\HasSpatial; /** * @property Point $location @@ -73,6 +74,8 @@ use MatanYadaev\EloquentSpatial\Objects\Polygon; */ class Place extends Model { + use HasSpatial; + protected $fillable = [ 'name', 'location', @@ -83,11 +86,6 @@ class Place extends Model 'location' => Point::class, 'area' => Polygon::class, ]; - - public function newEloquentBuilder($query): SpatialBuilder - { - return new SpatialBuilder($query); - } } ``` diff --git a/src/Traits/HasSpatial.php b/src/Traits/HasSpatial.php new file mode 100644 index 0000000..478ac43 --- /dev/null +++ b/src/Traits/HasSpatial.php @@ -0,0 +1,13 @@ + LineString::class, ]; - /** - * @param $query - * @return SpatialBuilder - */ - public function newEloquentBuilder($query): SpatialBuilder - { - // @phpstan-ignore-next-line - return new SpatialBuilder($query); - } - protected static function newFactory(): TestPlaceFactory { return new TestPlaceFactory;