From 0d16fb1700019fce7cc329d9a1b3b9987463f414 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 5 Mar 2020 07:56:27 +0000 Subject: [PATCH] Updates readme --- README.md | 126 +++++++++++++++++++++++++++--------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index d6fc3db..820016c 100644 --- a/README.md +++ b/README.md @@ -52,67 +52,6 @@ $jobs = Job::withinDistanceOf(53.957962, -1.085485, 20) ->orWithinDistanceOf(52.143542, -2.08556, 20); ``` -### Configuration - -When adding the `GeoScopeTrait` to your model you can define the latitude, longitude and distance units to be used by -the trait in the geoscope.php config file. - -```php - 'models' => [ - App\Job::class => [ - 'lat-column' => 'custom-lat-column-name', - 'long-column' => 'custom-long-column-name', - 'units' => 'meters' - ] - ] -``` - -Should you wish to use the scope for multiple latitude and longitude columns on the same model you can do so by creating -multiple configurations within the same model key. - -```php - 'models' => [ - App\Job::class => [ - 'location1' => [ - 'lat-column' => 'custom-lat-column-name', - 'long-column' => 'custom-long-column-name', - 'units' => 'meters' - ], - 'location2' => [ - 'lat-column' => 'custom-lat-column-name', - 'long-column' => 'custom-long-column-name', - 'units' => 'meters' - ] - ] - ] -``` -The key for the model config you wish to use can then be passed as a fourth parameter to -both the `withinDistanceOf` and `orWithinDistanceOf` scopes. - -```php - -$jobs = Job::withinDistanceOf(53.957962, -1.085485, 20, 'location1')->get(); - -$jobs2 = Job::withinDistanceOf(53.957962, -1.085485, 20, 'location1') - ->orWithinDistanceOf(52.143542, -2.08556, 20, 'location2'); -``` -You may also pass in an array of config items as the fourth parameter to both the `withinDistanceOf` and `orWithinDistanceOf` scopes. -```php - -$jobs = Job::withinDistanceOf(53.957962, -1.085485, 20, [ - 'lat-column' => 'lat-column-1', - 'long-column' => 'long-column-1', - 'units' => 'meters' - ])->get(); - -$jobs2 = Job::withinDistanceOf(53.957962, -1.085485, 20, 'location1') - ->orWithinDistanceOf(52.143542, -2.08556, 20, [ - 'units' => 'meters' - ])->get(); -``` -Any missing config options will be replaced with the defaults defined in `config('geoscope.defaults')`. -**Passing invalid config keys will also cause GeoScope to fallback to these defaults for all config fields.** - GeoScope also includes an `orderByDistanceFrom()` method that allows you to sort results by their distance from a specified lat long. ```php @@ -123,8 +62,6 @@ GeoScope also includes an `orderByDistanceFrom()` method that allows you to sort $results = Job::orderByDistanceFrom(30.1234, -71.2176, 'desc')->get(); ``` -### The `addDistanceFrom()` method - A field can be added to each returned result with the calculated distance from the given lat long using the `addDistanceFromField()` method. ```php @@ -185,6 +122,69 @@ A custom field name can be passed as the third argument to the `addDistanceFrom( } ``` +### Configuration + +When adding the `GeoScopeTrait` to your model you can define the latitude, longitude and distance units to be used by +the trait in the geoscope.php config file. + +```php + 'models' => [ + App\Job::class => [ + 'lat-column' => 'custom-lat-column-name', + 'long-column' => 'custom-long-column-name', + 'units' => 'meters' + ] + ] +``` + +Should you wish to use the scope for multiple latitude and longitude columns on the same model you can do so by creating +multiple configurations within the same model key. + +```php + 'models' => [ + App\Job::class => [ + 'location1' => [ + 'lat-column' => 'custom-lat-column-name', + 'long-column' => 'custom-long-column-name', + 'units' => 'meters' + ], + 'location2' => [ + 'lat-column' => 'custom-lat-column-name', + 'long-column' => 'custom-long-column-name', + 'units' => 'meters' + ] + ] + ] +``` +The key for the model config you wish to use can then be passed as a fourth parameter to +both the `withinDistanceOf` and `orWithinDistanceOf` scopes. + +```php + +$jobs = Job::withinDistanceOf(53.957962, -1.085485, 20, 'location1')->get(); + +$jobs2 = Job::withinDistanceOf(53.957962, -1.085485, 20, 'location1') + ->orWithinDistanceOf(52.143542, -2.08556, 20, 'location2'); +``` +You may also pass in an array of config items as the fourth parameter to both the `withinDistanceOf` and `orWithinDistanceOf` scopes. +```php + +$jobs = Job::withinDistanceOf(53.957962, -1.085485, 20, [ + 'lat-column' => 'lat-column-1', + 'long-column' => 'long-column-1', + 'units' => 'meters' + ])->get(); + +$jobs2 = Job::withinDistanceOf(53.957962, -1.085485, 20, 'location1') + ->orWithinDistanceOf(52.143542, -2.08556, 20, [ + 'units' => 'meters' + ])->get(); +``` +Any missing config options will be replaced with the defaults defined in `config('geoscope.defaults')`. +**Passing invalid config keys will also cause GeoScope to fallback to these defaults for all config fields.** + + + ## Database Query Builder Geoscope also allows you to call the `withinDistanceOf()`, `orWithinDistanceOf()` and `orderByDistanceFrom()` methods directly off the DB query builder: