Download the PHP package makidizajnerica/laravel-geolocation without Composer

On this page you can find all versions of the php package makidizajnerica/laravel-geolocation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-geolocation

Laravel GeoLocation

Laravel package to get the details about region, city, country, timezone, currency, etc. for a given IP address.

Installation

As for registering Service Provider, it is not necessary, Laravel will auto load provider using Package Discovery.

Usage

Using Facade

Return value of the MakiDizajnerica\GeoLocation\Facades\GeoLocation::lookup() is the instance of Illuminate\Support\Collection. To find out more about Laravel Collections head to Collections - Laravel.

You can also switch driver on runtime using:

Package comes with several predefined drivers, some of them require API_KEY to work. You can register those keys inside .env file:

Predefined drivers:

Driver URL
ipwhois [default] https://ipwhois.io/
geoplugin https://www.geoplugin.com/
abstractapi https://www.abstractapi.com/
ipdata https://ipdata.co/

Depending on the driver that is used it is possible to get different results.

Request Macro

Inside your controller Illuminate\Http\Request $request will have geolocation() method available:

Publishing Config File

To publish geolocation.php config file use command:

Creating Custom Driver

When creating custom driver, be sure to extend MakiDizajnerica\GeoLocation\GeoLocationDriver class. Then define two methods lookup() and format():

Method lookup($ipAddress) accepts one parametar of type string that represents IP address. Inside this method you write request logic (sending request, checking response etc.), after that you just need to return response data as array. If request is not successful for some reason, you may throw MakiDizajnerica\GeoLocation\Exceptions\GeoLocationDriverException that will be picked up and reported inside log files.

Method format($data) accepts one parametar of type array that represents your response data returned from lookup() method, here you can format data as array with your own set of key/value pairs.

Inside CustomDriver class you will have two methods available, options() and apiEndpoint().

Method options($key) accepts one parametar $key of type string and returns driver option based on provided $key.

Method apiEndpoint($ipAddress) accepts one parametar $ipAddress of type string and returns formatted api endpoint url with passed $ipAddress.

If you plan to use Laravel's built in Illuminate\Support\Facades\Http Http Client, you can use MakiDizajnerica\GeoLocation\Support\HandlingHttpResponse trait inside your CustomDriver class:

Method checkResponse(Response $response) accepts one parameter of type Illuminate\Http\Client\Response, then returns that response if it was successful, or otherwise throws MakiDizajnerica\GeoLocation\Exceptions\GeoLocationDriverException.

Method decodeResponseData(Response $response) accepts one parameter of type Illuminate\Http\Client\Response, then tries to json decode that response and return array containing response data, or empty array on fail.

Then when you wrote lookup logic and formatted data, you need to register your driver inside config/geolocation.php config file:

{ip} is placeholder where actual IP address will be placed on apiEndpoint() call. You can put placeholder either in api_endpoint:

or inside query_params like shown above:

You can also define any other placeholder wraped inside curly brackets like so:

Then on runtime pass array containing that placeholder as key as second parameter to driver() method:

So when you call apiEndpoint() method inside your driver lookup method, the return value should look something like this:

Author

Nemanja Marijanovic ([email protected])

Licence

Copyright © 2021, Nemanja Marijanovic [email protected]

All rights reserved.

For the full copyright and license information, please view the LICENSE file that was distributed within the source root of this package.


All versions of laravel-geolocation with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
laravel/framework Version >=9.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package makidizajnerica/laravel-geolocation contains the following files

Loading the files please wait ....