PHP code example of adamcmoore / nova-gmap

1. Go to this page and download the library: Download adamcmoore/nova-gmap 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/ */

    

adamcmoore / nova-gmap example snippets


NovaGmap::make('Location')

class Shop extends Model
{

	$fillable = [
		'title',
		'description',
		'address',
		'location_lat',
		'location_lng',
	];


	/*
	Provide the Location value to the Nova field
	*/
	public function getLocationAttribute()
	{
		return (object) [
			'latitude' => $this->location_lat,
			'longitude' => $this->location_lng,
		];
	}


	/*
	Transform the returned value from the Nova field
	*/
	public function setLocationAttribute($value)
	{
		$location_lat = round(object_get($value, 'latitude'), 7);
		$location_lng = round(object_get($value, 'longitude'), 7);
		$this->attributes['location_lat'] = $location_lat;
		$this->attributes['location_lng'] = $location_lng;
	}
}