1. Go to this page and download the library: Download netsells/laravel-geoscope 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/ */
netsells / laravel-geoscope example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
use Netsells\GeoScope\Traits\GeoScopeTrait;
class Job extends Model
{
use GeoScopeTrait;
//
}
// Gets all jobs within 20 miles of the given latitude and longitude
$jobs = Job::withinDistanceOf(53.957962, -1.085485, 20)->get();
// Gets all jobs within 20 miles of the first lat and long or within 20 miles
// of the second lat long
$jobs = Job::withinDistanceOf(53.957962, -1.085485, 20)
->orWithinDistanceOf(52.143542, -2.08556, 20);
// order by distance in ascending order
$results = Job::orderByDistanceFrom(30.1234, -71.2176, 'asc')->get();
// order by distance in descending order
$results = Job::orderByDistanceFrom(30.1234, -71.2176, 'desc')->get();
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Netsells\GeoScope\ScopeDriverFactory;
use App\Services\GeoScope\ScopeDrivers\PostgreSQLScopeDriver;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
app(ScopeDriverFactory::class)->registerDriverStrategy('pgsql', PostgreSQLScopeDriver::class);
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
}