Skip to content

Commit

Permalink
Updates readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hutchison committed Mar 5, 2020
1 parent a2bd09c commit 0d16fb1
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit 0d16fb1

Please sign in to comment.