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
- Host: GitHub
- URL: https://github.com/divineomega/laravel-geolocation-request
- Owner: DivineOmega
- License: lgpl-3.0
- Created: 2019-07-04T21:21:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-15T15:53:57.000Z (over 4 years ago)
- Last Synced: 2025-02-28T06:04:26.633Z (4 months ago)
- Topics: countries, geolocation, laravel-package, laravel-request
- Language: PHP
- Size: 10.7 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.