An open API service indexing awesome lists of open source software.

https://github.com/divineomega/laravel-geolocation-request

Laravel Geolocation Request
https://github.com/divineomega/laravel-geolocation-request

countries geolocation laravel-package laravel-request

Last synced: 3 months ago
JSON representation

Laravel Geolocation Request

Awesome Lists containing this project

README

        

# Laravel Geolocation Request

The Laravel Geolocation Request package provides an easy
way to geolocate requests to their country of origin, simply
by calling a `$request->country()` method.

## Installation

To install the Laravel Geolocation Request package, just
run the following Composer command.

```bash
composer require divineomega/laravel-geolocation-request
```

## Usage

To use geolocation enabled requests within your Laravel controller
methods, you can replace the `use Illuminate\Http\Request` line
at the top of your controllers, as shown in the usage example below.

Once done, you can simple call the `$request->country()` method to
perform geolocation and return the origin country of the active
request based on its IP address. The country is returned as an object
containing many properties, such as the country name and ISO codes.

```php
country();

$user = new \App\User();
$user->name = $request->name;
$user->countryName = $country->name;
$user->countryCode = $country->isoCodeAlpha3;

$user->save();

// ...
}
}
```

If you are using custom request objects, you can
change them to extend the provided `GeolocationRequest` class.
If you unable to extend your custom request object, or
simply do not wish to, you can add geolocation functionality
by using the provided `GeolocatableRequest` trait.