Download the PHP package harrisonratcliffe/ip-api-laravel without Composer
On this page you can find all versions of the php package harrisonratcliffe/ip-api-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download harrisonratcliffe/ip-api-laravel
More information about harrisonratcliffe/ip-api-laravel
Files in harrisonratcliffe/ip-api-laravel
Package ip-api-laravel
Short Description A simple Laravel package to get IP address information from ip-api.com
License MIT
Informations about the package ip-api-laravel
IP-Api Laravel - IP Address Information Lookup
The IpApiLaravel package provides an easy-to-use interface for looking up information about IP addresses using the ip-api-laravel.com API. It allows you to fetch various details about an IP address, such as geographical location, time zone, currency, and more.
This package is a fork of el-factory/ip-api with additional features.
Requirements
- PHP 7.2 or higher
- Laravel 7 or higher
Installation
The IpApiLaravel package requires Laravel version 7 or higher.
To install the package, you can use Composer:
Configuration
After installing the package, you can optionally publish the configuration file to customize the default settings:
This will create a ip-api-laravel.php file in the config directory of your Laravel application. You can modify the default configuration values in this file according to your specific requirements.
Usage
IP Address Lookup
To perform an IP address lookup, you can use the lookup method on the IpApiLaravel class:
This will return an array with the details of the provided IP address.
Additional Configuration
You can also customize the IP address lookup by using the following methods:
fields(array $fields): IpApiLaravel
Set the fields to be included in the API response. The $fields parameter should be an array of fields you want to retrieve.
usingKey(string $apiKey): IpApiLaravel
By default, the package uses the API key provided in the config file. If you wish to send a different API key for a specific request, you can use the usingKey method to set the API key for that request.
retry(int $times, int $sleep): IpApiLaravel
Set the retry configuration for failed API requests. The $times parameter represents the number of retry attempts, and the $sleep parameter specifies the number of seconds to sleep between retries.
lang(string $language): IpApiLaravel
Set the language for the API response. The $language parameter should be a two-letter language code.
withHeaders(): IpApiLaravel
Include request limit and remaining requests headers in the API response.
timeout(int $seconds): IpApiLaravel
Set a timeout for the API request. The $seconds parameter specifies the maximum number of seconds to wait for a response. If the request times out, an exception will be thrown.
Console Command - ip-api-laravel:connection
The IpApiLaravel package also includes a console command named ip-api-laravel:connection that allows you to test the connection to the ip-api-laravel.com API with a specific IP address or your public IP address (if not provided).
To use the command, run the following Artisan command:
{ip}(optional): The IP address to test with. If not provided, the command will use your public IP address.
The command will display the details retrieved from the ip-api-laravel.com API for the provided IP address.
Example
Here's an example of using the ip-api-laravel:connection command:
This will test the connection to ip-api-laravel.com API with the specified IP address and display the details retrieved.
If no IP address is provided, the command will automatically use your public IP address:
Exceptions
The IpApiLaravel class may throw the following exceptions:
Exception: If the provided IP address is invalid or reserved.RequestException: If an error occurs while making the API request.
License
The IpApiLaravel package is open-source software licensed under the MIT License. Feel free to use and modify it according to your needs.