Skip to content

Commit

Permalink
Merge pull request #32 from flaviosilveira/master
Browse files Browse the repository at this point in the history
Improve Geographical documentation
  • Loading branch information
malhal authored Feb 14, 2023
2 parents 9164923 + e5007a1 commit 642d080
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ $table->double('longitude');
$table->double('latitude');
```

Finally in your model use:
Finally, edit you model to use the Geographical Trait, as the example below:
```php
use Geographical;
<?php

namespace App\Models;

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

class ModelExample extends Model
{
use Geographical;
```

### 1. Distance

Find the distance to all the entries in your table from a particular location.

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

Expand All @@ -27,7 +36,7 @@ $asc = $query->orderBy('distance', 'ASC')->get();
Find all the entries in your table inside a circular geo-fence.

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

Expand All @@ -45,7 +54,7 @@ protected static $kilometers = true;
1. The method returns a `Eloquent\Builder` object so that you can add optional conditions if you want.
2. If you require to select only a certain columns, it can be achieved by using `select()`.
```php
Model::select('id', 'name')->distance($latitude, $longitude);
ModelExample::select('id', 'name')->distance($latitude, $longitude);
```
(`select()` should precede the `distance()/geofence()`)
3. You can use `distance` as an aggregate column in the result.
Expand Down

0 comments on commit 642d080

Please sign in to comment.