{"id":28744189,"url":"https://github.com/ipinfo/laravel","last_synced_at":"2025-06-16T11:11:01.399Z","repository":{"id":33182035,"uuid":"150529097","full_name":"ipinfo/laravel","owner":"ipinfo","description":"Official Laravel client library for IPinfo API (IP geolocation and other types of IP data)","archived":false,"fork":false,"pushed_at":"2025-05-08T17:41:48.000Z","size":406,"stargazers_count":188,"open_issues_count":8,"forks_count":41,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-06-13T11:55:45.006Z","etag":null,"topics":["ip-address","ip-data","ip-geolocation","ipinfo","laravel"],"latest_commit_sha":null,"homepage":"https://ipinfo.io","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipinfo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-27T04:32:54.000Z","updated_at":"2025-06-10T03:07:24.000Z","dependencies_parsed_at":"2024-06-19T00:17:14.883Z","dependency_job_id":null,"html_url":"https://github.com/ipinfo/laravel","commit_stats":{"total_commits":85,"total_committers":13,"mean_commits":6.538461538461538,"dds":0.6470588235294117,"last_synced_commit":"fac542489446d813c01db7b8a9fb38fc2ac51c78"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ipinfo/laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Flaravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Flaravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Flaravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Flaravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipinfo","download_url":"https://codeload.github.com/ipinfo/laravel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Flaravel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260148401,"owners_count":22965915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ip-address","ip-data","ip-geolocation","ipinfo","laravel"],"created_at":"2025-06-16T11:11:00.704Z","updated_at":"2025-06-16T11:11:01.387Z","avatar_url":"https://github.com/ipinfo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [\u003cimg src=\"https://ipinfo.io/static/ipinfo-small.svg\" alt=\"IPinfo\" width=\"24\"/\u003e](https://ipinfo.io/) IPinfo Laravel Client Library\n\nThis is the official Laravel client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to look up your own IP address, or get any of the following details for an IP:\n - [IP geolocation](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)\n - [ASN details](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)\n - [Company information](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)\n - [Carrier details](https://ipinfo.io/ip-carrier-api) (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)\n\nCheck all the data we have for your IP address [here](https://ipinfo.io/what-is-my-ip).\n\n### Getting Started\n\nYou'll need an IPinfo API access token, which you can get by signing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup?ref=lib-Laravel).\n\nThe free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing).\n\n⚠️ Note: This library does not currently support our newest free API https://ipinfo.io/lite. If you’d like to use IPinfo Lite, you can call the [endpoint directly](https://ipinfo.io/developers/lite-api) using your preferred HTTP client. Developers are also welcome to contribute support for Lite by submitting a pull request.\n\n#### Installation\n\n```\ncomposer require ipinfo/ipinfolaravel\n```\n\nOpen your application's `\\app\\Http\\Kernel.php` file and add the following to the `Kernel::middleware` property:\n\n```php\nprotected $middleware = [\n    ...\n    \\ipinfo\\ipinfolaravel\\ipinfolaravel::class,\n];\n```\n\n#### Quick Start\n\n```php\nRoute::get('/', function (Request $request) {\n    $location_text = \"The IP address {$request-\u003eipinfo-\u003eip}.\";\n    return view('index', ['location' =\u003e $location_text]);\n});\n```\n\nwill return the following string to the `index` view:\n\n```\n\"The IP address 127.0.0.1.\"\n```\n\n### Authentication\n\nThe IPinfo library can be authenticated with your IPinfo API token. It also works without an authentication token, but in a more limited capacity. To set your access token, add the following to your app's `\\config\\services.php` file and replace `{{access_token}}` with your own token:\n\n```php\n'ipinfo' =\u003e [\n    'access_token' =\u003e {{access_token}},\n],\n```\n\nTo do this in a more secure manner and avoid putting secret keys in your codebase, create an `IPINFO_SECRET` (or similar) environment variable and access this value from within `\\config\\services.php`, like so:\n\n```php\n'ipinfo' =\u003e [\n    'access_token' =\u003e env('IPINFO_SECRET'),\n],\n```\n\n### Details Data\n\n`$request-\u003eipinfo` is a `Details` object that contains all fields listed [IPinfo developer docs](https://ipinfo.io/developers/responses#full-response) with a few minor additions. Properties can be accessed directly.\n\n```php\n\u003e\u003e\u003e $request-\u003eipinfo-\u003ehostname\ncpe-104-175-221-247.socal.res.rr.com\n```\n\n#### Country Name\n\n`$request-\u003eipinfo-\u003ecountry_name` will return the country name, as supplied by the `countries.json` file. See below for instructions on changing that file for use with non-English languages. `$request-\u003eipinfo-\u003ecountry` will still return the country code.\n\n```php\n\u003e\u003e\u003e $request-\u003eipinfo-\u003ecountry\nUS\n\u003e\u003e\u003e $request-\u003eipinfo-\u003ecountry_name\nUnited States\n```\n\n#### Accessing all properties\n\n`$request-\u003eipinfo-\u003eall` will return all details data as an array.\n\n```php\n\u003e\u003e\u003e $request-\u003eipinfo-\u003eall\n{\n'asn': {  'asn': 'AS20001',\n           'domain': 'twcable.com',\n           'name': 'Time Warner Cable Internet LLC',\n           'route': '104.172.0.0/14',\n           'type': 'isp'},\n'city': 'Los Angeles',\n'company': {   'domain': 'twcable.com',\n               'name': 'Time Warner Cable Internet LLC',\n               'type': 'isp'},\n'country': 'US',\n'country_name': 'United States',\n'hostname': 'cpe-104-175-221-247.socal.res.rr.com',\n'ip': '104.175.221.247',\n'ip_address': IPv4Address('104.175.221.247'),\n'loc': '34.0293,-118.3570',\n'latitude': '34.0293',\n'longitude': '-118.3570',\n'phone': '323',\n'postal': '90016',\n'region': 'California'\n}\n```\n\n### Caching\n\nIn-memory caching of `Details` data is provided by default via Laravel's file-based cache. LRU (least recently used) cache-invalidation functionality has been added to the default TTL (time to live). This means that values will be cached for the specified duration; if the cache's max size is reached, cache values will be invalidated as necessary, starting with the oldest cached value.\n\n#### Modifying cache options\n\nDefault cache TTL and maximum size can be changed by setting values in the `$settings` argument array.\n\n* Default maximum cache size: 4096 (multiples of 2 are recommended to increase efficiency)\n* Default TTL: 24 hours (in minutes)\n\n```php\n'ipinfo' =\u003e [\n    'cache_maxsize' =\u003e {{cache_maxsize}},\n    'cache_ttl' =\u003e {{cache_ttl}},\n],\n```\n\n#### Using a different cache\n\nIt is possible to use a custom cache by creating a child class of the [CacheInterface](https://github.com/ipinfo/php/blob/master/src/cache/CacheInterface.php) class and setting the the `cache` config value in `\\config\\services.php`. FYI this is known as [the Strategy Pattern](https://sourcemaking.com/design_patterns/strategy).\n\n```php\n'ipinfo' =\u003e [\n    ...\n    'cache' =\u003e new MyCustomCacheObject(),\n],\n```\n\n### IP Selection Mechanism\n\nBy default, the IP from the incoming request is used.\n\nSince the desired IP by your system may be in other locations, the IP selection mechanism is configurable and some alternative built-in options are available.\n\n#### Using built-in ip selectors\n\n##### DefaultIPSelector\n\nA [DefaultIPSelector](https://github.com/ipinfo/php/blob/master/src/iphandler/DefaultIPSelector.php) is used by default if no IP selector is provided. It returns the source IP from the incoming request.\n\nThis selector can be set explicitly by setting the `ip_selector` config value in `\\config\\services.php`.\n\n```php\n'ipinfo' =\u003e [\n    'ip_selector' =\u003e new DefaultIPSelector(),\n],\n```\n\n##### OriginatingIPSelector\n\nA [OriginatingIPSelector](https://github.com/ipinfo/php/blob/master/src/iphandler/OriginatingIPSelector.php) selects an IP address by trying to extract it from the `X-Forwarded-For` header. This is not always the most reliable unless your proxy setup allows you to trust it. It will default to the source IP on the request if the header doesn't exist.\n\nThis selector can be set by setting the `ip_selector` config value in `\\config\\services.php`.\n\n```php\n'ipinfo' =\u003e [\n    'ip_selector' =\u003e new OriginatingIPSelector(),\n],\n```\n\n#### Using a custom IP selector\n\nIn case a custom IP selector is required, you may implement the [IPHandlerInterface](https://github.com/ipinfo/php/blob/master/src/iphandler/IPHandlerInterface.php) interface and set the `ip_selector` config value in `\\config\\services.php`.\n\nFor example:\n\n```php\n'ipinfo' =\u003e [\n    ...\n    'ip_selector' =\u003e new CustomIPSelector(),\n],\n```\n\n### Internationalization\n\nWhen looking up an IP address, the response object includes a `$request-\u003eipinfo-\u003ecountry_name` property which includes the country name based on American English. It is possible to return the country name in other languages by telling the library to read from a custom file. To define a custom file, add the following to your app's `\\config\\services.php` file and replace `{{countries}}` with your own file path.\n\n```php\n'ipinfo' =\u003e [\n    ...\n    'countries_file' =\u003e {{countries}},\n],\n```\n\nThe file must be a `.json` file with the following structure:\n\n```\n{\n    {{country_code}}: {{country_name}},\n    \"BD\": \"Bangladesh\",\n    \"BE\": \"Belgium\",\n    \"BF\": \"Burkina Faso\",\n    \"BG\": \"Bulgaria\"\n    ...\n}\n```\n\n### Filtering\n\nBy default, `ipinfolaravel` filters out requests that have `bot` or `spider` in the user-agent. Instead of looking up IP address data for these requests, the `$request-\u003eipinfo` attribute is set to `null`. This is to prevent you from unnecessarily using up requests on non-user traffic. This behavior can be switched off by adding the following to your app's `\\config\\services.php` file.\n\n```php\n'ipinfo' =\u003e [\n    ...\n    'filter' =\u003e false,\n ],\n```\n\nTo set your own filtering rules, *thereby replacing the default filter*, you can set `ipinfo.config` to your own, custom callable function which satisfies the following rules:\n\n* Accepts one request.\n* Returns *True to filter out, False to allow lookup*\n\nTo use your own filter function:\n\n```php\n'ipinfo' =\u003e [\n    ...\n    'filter' =\u003e $customFilterFunction,\n],\n```\n\n### Suppressing Exceptions\n\nLaravel middleware does not allow you to catch exceptions from other\nmiddleware, so if the IPinfo middleware throws an exception, it'll be quite\nhard to deal with it.\n\nWe allow suppressing exceptions by specifying the `no_except` key in the\nconfig:\n\n```php\n'ipinfo' =\u003e [\n    ...\n    'no_except' =\u003e true,\n],\n```\n\nIf an exception occurs when this setting is `true`, the `$request-\u003eipinfo`\nobject will be equal to `null`.\n\n### Trying test application with Laravel Sail\n\nInstall Laravel Sail with:\n```bash\ncd testapp\n\ndocker run --rm -u \"$(id -u):$(id -g)\" -v \"$(pwd):/var/www/html\" -w /var/www/html laravelsail/php84-composer:latest composer install --ignore-platform-reqs\n\n./vendor/bin/sail build --no-cache\n\n./vendor/bin/sail up\nAPP_KEY=$(./vendor/bin/sail artisan key:generate --show)\necho \"APP_KEY=${APP_KEY}\" \u003e .env\n# kill 'sail up' process\n\necho \"IPINFO_TOKEN=\u003cYOUR_TOKEN\u003e\" \u003e app/.env\n\n./vendor/bin/sail up\n```\n\nVisit http://0.0.0.0:80. You should see a message similar to:\n```\nHello world!\n\nDetails: The IP address 172.20.0.1.\n```\n\nTo run tests within `testapp` while Sail is up:\n\n```bash\n./vendor/bin/sail phpunit\n```\n\n### Other Libraries\n\nThere are official IPinfo client libraries available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. There are also many third-party libraries and integrations available for our API.\n\n### About IPinfo\n\nFounded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.\n\n[![image](https://avatars3.githubusercontent.com/u/15721521?s=128\u0026u=7bb7dde5c4991335fb234e68a30971944abc6bf3\u0026v=4)](https://ipinfo.io/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Flaravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipinfo%2Flaravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Flaravel/lists"}