{"id":14973954,"url":"https://github.com/artisanweblab/spatial","last_synced_at":"2025-10-24T05:31:56.816Z","repository":{"id":57680781,"uuid":"494775093","full_name":"ArtisanWebLab/spatial","owner":"ArtisanWebLab","description":"Spatial package (PostgreSQL, PostGIS, MySQL, MariaDB) for Laravel Framework","archived":false,"fork":false,"pushed_at":"2024-04-28T11:20:42.000Z","size":21,"stargazers_count":1,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"1.x","last_synced_at":"2025-01-31T00:13:19.556Z","etag":null,"topics":["eloquent","laravel","mariadb","mysql","pgsql","postgis","postgresql","spatial"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArtisanWebLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-21T12:20:01.000Z","updated_at":"2024-08-05T15:06:42.000Z","dependencies_parsed_at":"2023-01-21T02:15:36.603Z","dependency_job_id":"a2977be0-ef51-42d1-862b-0535c19bc574","html_url":"https://github.com/ArtisanWebLab/spatial","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"97e973b97c31e42a04d1b8649438a4a0a0cd3f00"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtisanWebLab%2Fspatial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtisanWebLab%2Fspatial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtisanWebLab%2Fspatial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtisanWebLab%2Fspatial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtisanWebLab","download_url":"https://codeload.github.com/ArtisanWebLab/spatial/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237918710,"owners_count":19387305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","laravel","mariadb","mysql","pgsql","postgis","postgresql","spatial"],"created_at":"2024-09-24T13:49:44.089Z","updated_at":"2025-10-24T05:31:49.405Z","avatar_url":"https://github.com/ArtisanWebLab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Spatial\n\n```shell\ncomposer require artisanweblab/spatial\n```\n\n## PostgreSQL and PostGIS\n\nPostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL.\n\n[PostGIS Official Documentation](https://postgis.net/documentation)\n\n[Install PostGIS to your Web server](https://postgis.net/install/)\n\n[Install PostGIS to your Docker container](https://github.com/postgis/docker-postgis)\n\n## MySQL and MariaDB\n\nMySQL and MariaDB have built-in support for spatial data.\n\n## Integration with your project\n\n### Prepare your table\n\nAdd fields with the required data type:\n\nLaravel 10 and before:\n\n```php\n$table-\u003epoint('point')-\u003eisGeometry()-\u003enullable();\n```\n\nLaravel 11 and after:\n\n```php\n$table-\u003egeometry('point', 'point')-\u003enullable();\n```\n\n### Prepare your model\n\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse ArtisanWebLab\\Spatial\\Eloquent\\Casts\\SpatialCast;\nuse ArtisanWebLab\\Spatial\\Traits\\SpatialTrait;\nuse Brick\\Geo\\Point;\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\n\n/**\n * @property integer $id\n * @property string $name\n * @property Point $point\n */\nclass User extends Model\n{\n    use HasFactory, SpatialTrait;\n\n    protected $fillable = [\n        'name',\n        'address',\n        'point',\n    ];\n\n    protected $casts = [\n        'point' =\u003e SpatialCast::class,\n    ];\n}\n```\n\n### Example of Input and Output spatial data\n\n```php\n\u003c?php\n\nuse App\\Models\\User;\nuse Brick\\Geo\\Point;\n\n/** @var User $user */\n$user = User::query()-\u003efirst();\n\n// Longitude, Latitude\n$user-\u003epoint = Point::xy(2.2945022, 48.8582687);\n\n$user-\u003esave();\n\n//...\n\n$user = User::query()-\u003efirst();\n\nget_class($user-\u003epoint); // Brick\\Geo\\Point\n```\n\n### How to find records by Geometry\n\n```php\n\u003c?php\n\nuse App\\Models\\User;\nuse Brick\\Geo\\Point;\n\n// Longitude, Latitude\n$point = Point::xy(2.2945022, 48.8582687);\n\n$users = User::query()\n    -\u003ewithSpatialDistance('point', $point)\n    -\u003ewhereSpatialDistanceSphere('point', $point, '\u003c=', 1000) // 1000 meters\n    -\u003eget();\n```\n\n### Available Eloquent methods\n\n```php\nwithSpatialDistance(string $column, Geometry $geometry, string $alias = null): Builder\n\nwhereSpatialDistance(string $column, Geometry $geometry, string $operator, int|float $distance, string $boolean = 'and'): Builder\n\norWhereSpatialDistance(string $column, Geometry $geometry, string $operator, int|float $distance): Builder\n```\n\n## Geometry Raw\n\n```php\nuse Brick\\Geo\\IO\\GeoJSONReader;\nuse Brick\\Geo\\IO\\GeoJSONWriter;\nuse Brick\\Geo\\Point;\nuse Illuminate\\Support\\Facades\\DB;\n\n// Longitude, Latitude\n$point = Point::xy(2.2945022, 48.8582687);\n\n$query = sprintf(\n    \"ST_AsGeoJSON(ST_Buffer(ST_GeomFromGeoJSON('%s'), 10)) as response\",\n    (new GeoJSONWriter(false))-\u003ewrite($point)\n);\n\n$result = DB::query()-\u003eselectRaw($query)-\u003efirst();\n\n$geometry = $result ? (new GeoJSONReader(true))-\u003eread($result-\u003eresponse) : null;\n```\n\n```json\n{\n    \"type\":\"Polygon\",\n    \"coordinates\":[\n        [\n            [58.8582687,2.2945022],\n            [58.666121504,0.34359898],\n            //...\n        ]\n    ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartisanweblab%2Fspatial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartisanweblab%2Fspatial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartisanweblab%2Fspatial/lists"}