PHP code example of encima-io / nova-coordinates-postgis-fields

1. Go to this page and download the library: Download encima-io/nova-coordinates-postgis-fields library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

encima-io / nova-coordinates-postgis-fields example snippets


use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

public function up()
{
    Schema::create('locations', function (Blueprint $table) {
        // ...
        $table->string('street_address')->nullable();
        $table->geometry('position')->nullable(); // Creates a geography type column
        // ...
    });
}

use Encima\PostGIS\Latitude;
use Encima\PostGIS\Longitude;
use Laravel\Nova\Fields\Place;

Place::make('Street address', 'street_address')
    ->latitude('latitude')
    ->longitude('longitude'),
Latitude::make('Latitude', 'latitude'),
Longitude::make('Longitude', 'longitude'),

// latitude with the alias : 'lat_property'
// longitude with the alias : 'lon_propery'
Place::make('Street address', 'street_address')
    ->latitude('lat_property')
    ->longitude('lon_propery'),

// We inform the Latitude-field about its sibling key, longitude, through
// the longitude method. The key should match the key used in the Place field
Latitude::make('Latitude', 'lat_property')
    ->longitude('lon_propery'),

// We do the same, but now for the latitude method
Longitude::make('Longitude', 'lon_propery')
    ->latitude('lat_property'),

Place::make('Street address', 'street_address')
    ->latitude('latitude')
    ->longitude('longitude'),
Latitude::make('Latitude', 'latitude')
    ->fromPosition('location'),
Longitude::make('Longitude', 'longitude')
    ->fromPosition('location'),

Latitude::make('Latitude', 'latitude')
    ->dataType('geometry'),
Longitude::make('Longitude', 'longitude')
    ->dataType('geometry'),

Place::make('Street address', 'street_address')
    ->latitude('latitude')
    ->longitude('longitude'),
Latitude::make('Latitude', 'latitude')
    ->cacheStore('file')
    ->cacheFor('300 seconds'),
Longitude::make('Longitude', 'longitude')
    ->cacheStore('array')
    ->cacheFor(now()->addDay()),



namespace App\Nova;

use Encima\PostGIS\Latitude;
use Encima\PostGIS\Longitude;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Place;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Panel;


class UserAddress extends Resource
{

    // ...

    public function fields(Request $request)
    {
        return [
            // Other fields
            // ...
            new Panel('Address Information', [
                Place::make('Street address', 'street_address')
                    ->postalCode('postal_code')
                    ->city('postal_town')
                    ->latitude('latitude')
                    ->longitude('longitude'),
                Text::make('Postal code', 'postal_code')
                    ->sortable(),
                Text::make('Postal town', 'postal_town')
                    ->sortable(),
                Latitude::make('Latitude', 'latitude')
                    ->longitude('longitude')
                    ->fromPosition('position')
                    ->cacheFor('15 minutes'),
                Longitude::make('Longitude', 'longitude')
                    ->latitude('latitude')
                    ->fromPosition('position')
                    ->cacheFor('15 minutes'),
            ])
        ];
    }
}