Download the PHP package encima-io/nova-coordinates-postgis-fields without Composer
On this page you can find all versions of the php package encima-io/nova-coordinates-postgis-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download encima-io/nova-coordinates-postgis-fields
More information about encima-io/nova-coordinates-postgis-fields
Files in encima-io/nova-coordinates-postgis-fields
Package nova-coordinates-postgis-fields
Short Description A Laravel Nova field for updating PostGIS geography and geometry columns.
License MIT
Informations about the package nova-coordinates-postgis-fields
Laravel Nova PostGIS Coordinates Field
Encima is a web-development team based in Oslo, Norway. You'll find more information about us on our website.
This package is made to allow you to easily view and update your PostGIS "geography" and "geometry" fields with Laravel Nova. To use this package you should of course already be using PostgreSQL with the PostGIS extension.
Installation
NB! This package is designed to be used for a POINT, a single location. If you are looking for something to update lines or multiple positions, then this package is not for you.
You can install the package via composer:
Usage
Migrations
You should have a column on the models table that is of the "geometry" type. This will create a "geography" type column on your table in the PostgreSQL database. This package also supports the "geometry" type.
Resource
On the Nova resource you should use the Encima\PostGIS\Latitude
and Encima\PostGIS\Longitude
fields in addition to the standard Laravel\Nova\Fields\Place
field.
The values passed to the latitude()
and longitude()
methods on the Place
field must be the same values as you pass to the second parameter in the Latitude
and Longitude
fields, see the example below. This is the ensures that the coordinates fetched by the Algolia API will get sent to the Latitude
and Longitude
fields.
Custom key-names on fields
If you however use the latitude
and longitude
keys for something else on you model, like an accessor or a column in your database, then you should change the keys to something thats available. When you use custom keys you need to let the fields know about their siblings field-key like this.
Column name
By default this package assumes your geography/geometry field is named position
. If you are using another name for he column then you can specify this through the fromPosition(string $column)
method. Here is an example, using the column name location
:
Geometry
If your position column is of the geometry type, then you need to specify this through the dataType(string $name)
method.
Cache
This package uses Laravels Cache facade, \Illuminate\Support\Facades\Cache
, to reduce the amount of queries to the database. Since the coordinates needs a little trip to the database to be converted to the right format, we cache the result by default for 5 minutes, or until they are updated from the edit page.
For caching it uses your default cache store. You can change the cache store by with the cacheStore(string $store)
method. You can also change the lifetime of the cache by using the cacheFor($ttl)
method.
Example
Full example for a resource:
Disclaimer
There is some use of the DB::raw()
method in this package. We have tried to sanitize the parameters, but you never know. Use this package at your own risk!
License
The MIT License (MIT). Please see License File for more information.