danhunsaker / laravel-spatial
Laravel 的空间数据类型扩展。
v1.0.1
2020-07-30 21:07 UTC
Requires
- php: ^7.2
- doctrine/dbal: ^2.5
- funiq/geophp: dev-master
- illuminate/database: ^5.7 || ^6.0 || ^7.0
- jmikola/geojson: ^1.0
Requires (Dev)
- laravel/laravel: ^7.0
- mockery/mockery: 1.3.*
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-20 13:01:49 UTC
README
此包完全未记录文档且不稳定,是两个优秀包的结合
安装
使用 composer 使安装变得非常简单
composer require danhunsaker/laravel-spatial
要求
与已安装的 PostgreSQL 及其扩展 PostGIS 以及至少版本 5.6 的 MySQL 兼容。
如果尝试在不符合这些要求的共享主机上使用,请更换提供商。
用法
迁移
像其他字段一样添加空间字段到您的迁移中
$table->point('point_column'); $table->linestring('line_string_column'); $table->polygon('polygon_column'); $table->geometry('geometry_column'); $table->multipoint('multi_point_column'); $table->multilinestring('multi_line_string_column'); $table->multipolygon('multi_polygon_column'); $table->geometrycollection('geometry_collection_column');
模型
使用空间字段的任何模型都需要使用 LaravelSpatial\Eloquent\SpatialTrait
,并在 $spatialFields
属性中列出空间字段本身
use LaravelSpatial\Eloquent\SpatialTrait; // ... class MyModel extends Model { use SpatialTrait; // ... protected $spatialFields = ['location']; // ... }
值
我们使用 GeoJson PHP 库 来描述空间字段作为 GeoJSON 对象,例如。
use GeoJSON\Geometry\Point; // ... $eloquent = new MyModel(); $eloquent->location = new Point([49.7, 6.9]); // ... $eloquent->save();