PHP code example of malhal / laravel-geographical

1. Go to this page and download the library: Download malhal/laravel-geographical 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/ */

    

malhal / laravel-geographical example snippets


$table->double('longitude');
$table->double('latitude');



namespace App\Models;

use Malhal\Geographical\Geographical;
use Illuminate\Database\Eloquent\Model;

class ModelExample extends Model
{
    use Geographical;

$query = ModelExample::distance($latitude, $longitude);
$asc = $query->orderBy('distance', 'ASC')->get();
 

$query = ModelExample::geofence($latitude, $longitude, $inner_radius, $outer_radius);
$all = $query->get();

protected static $kilometers = true;

    ModelExample::select('id', 'name')->distance($latitude, $longitude);
    

    const LATITUDE  = 'lat';
    const LONGITUDE = 'lng';
    

    $query = Model::distance($latitude, $longitude, $options);
    

    $options = [
       'table' => 'coordinates',
       'latitude_column' => 'lat',
       'longitude_column' => 'lon'
    ]
   
    Model::select('id', 'name')->distance($latitude, $longitude, $options);
    

   
   Model::join('locations', function($join){ 
               $join->on('model.id', '=', 'locations.model_id');
           })
           ->select('id', 'name')
           ->distance($latitude, $longitude, ['table' => 'locations']);