Download the PHP package matanyadaev/laravel-eloquent-spatial without Composer
On this page you can find all versions of the php package matanyadaev/laravel-eloquent-spatial. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download matanyadaev/laravel-eloquent-spatial
More information about matanyadaev/laravel-eloquent-spatial
Files in matanyadaev/laravel-eloquent-spatial
Package laravel-eloquent-spatial
Short Description Spatial library for Laravel
License MIT
Homepage https://github.com/matanyadaev/laravel-eloquent-spatial
Informations about the package laravel-eloquent-spatial
Laravel Eloquent Spatial
This package allows you to easily work with spatial data types and functions in Laravel and standalone Eloquent projects.
Supported databases:
- MySQL 8.4
- MariaDB 10.11
- Postgres 14/15/16/17/18 with PostGIS 3.4/3.5/3.6
Getting Started
Installing the Package
You can install the package via composer:
Setting Up Your First Model
-
First, generate a new model along with a migration file by running:
-
Next, add some spatial columns to the migration file. For instance, to create a "places" table:
-
Run the migration:
- In your new model, fill the
$fillableand$castsarrays and use theHasSpatialtrait:
Interacting with Spatial Data
After setting up your model, you can now create and access spatial data. Here's an example:
Standalone Eloquent Usage (without Laravel)
This package also works in projects that use Eloquent on its own, without the full Laravel framework.
Just boot Eloquent — for example, with Illuminate\Database\Capsule\Manager — and the spatial casts, scopes, and objects are ready to use:
From there, models, casts, and query scopes behave exactly as in the examples above.
Further Reading
For more comprehensive documentation on the API, please refer to the API page.
Extension
Extend Geometry class with macros
You can add new methods to the Geometry class through macros.
Here's an example of how to register a macro in your service provider's boot method:
Use the method in your code:
Extend with custom geometry classes
You can extend the geometry classes by creating custom geometry classes and add functionality. You can also override existing methods, although it is not recommended, as it may lead to unexpected behavior.
-
Create a custom geometry class that extends the base geometry class.
-
Update the geometry class mapping in a service provider file.
-
Update your model to use the custom geometry class in the
$castsproperty orcasts()method. - Use the custom geometry class in your code.
Set default SRID
By default, the SRID is set to 0 (EPSG:0).
You can set the default SRID for your application by setting the SRID constant in a service provider's boot method:
Development
Here are some useful commands for development:
- Run tests:
composer pest:mysql,composer pest:mariadb,composer pest:postgres - Run tests with coverage:
composer pest-coverage:mysql - Perform type checking:
composer phpstan - Perform code formatting:
composer pint
Before running tests, make sure to run docker-compose up to start the database container.
Updates and Changes
For details on updates and changes, please refer to our CHANGELOG.
License
Laravel Eloquent Spatial is released under The MIT License (MIT). For more information, please see our License File.
All versions of laravel-eloquent-spatial with dependencies
ext-json Version *
ext-pdo Version *
brick/geo Version 0.13.*
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0