{"id":17343113,"url":"https://github.com/danielme85/laravel-geoip2","last_synced_at":"2026-03-07T17:33:02.226Z","repository":{"id":54700659,"uuid":"74390285","full_name":"danielme85/laravel-geoip2","owner":"danielme85","description":"Service provider and DB downloader for Maxminds PHP API GeoIP2.","archived":false,"fork":false,"pushed_at":"2021-02-03T06:31:41.000Z","size":126,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-10T12:43:49.177Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielme85.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-21T17:53:12.000Z","updated_at":"2025-04-23T06:29:15.000Z","dependencies_parsed_at":"2022-08-14T00:30:33.886Z","dependency_job_id":null,"html_url":"https://github.com/danielme85/laravel-geoip2","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/danielme85/laravel-geoip2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Flaravel-geoip2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Flaravel-geoip2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Flaravel-geoip2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Flaravel-geoip2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielme85","download_url":"https://codeload.github.com/danielme85/laravel-geoip2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielme85%2Flaravel-geoip2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30223380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T17:00:40.062Z","status":"ssl_error","status_checked_at":"2026-03-07T17:00:39.026Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-10-15T16:08:25.999Z","updated_at":"2026-03-07T17:33:02.194Z","avatar_url":"https://github.com/danielme85.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel-geoip2\nLaravel 5+ Service provider and DB downloader for Maxminds PHP API GeoIP2.\nhttps://github.com/maxmind/GeoIP2-php\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://travis-ci.org/danielme85/laravel-geoip2.svg?branch=master)](https://travis-ci.org/danielme85/laravel-geoip2)\n\n\u003cb\u003ePer Jan 2020 you now have to create an account at MaxMind and get a \"license key\". It is still free of charge per now.\u003c/b\u003e\n\n[https://dev.maxmind.com/geoip/geoip2/geolite2/](https://dev.maxmind.com/geoip/geoip2/geolite2/)\n\n### Install\nIn composer.json\n ```\n \"require\": {\n         \"danielme85/laravel-geoip2\": \"dev-master\",\n         ....\n }\n ```\n or command: composer require danielme85/laravel-geoip2\n \n Add your geoip licence to your env file:\n ```\nGEOIP2_LICENSE=XXXXX\n```\n\n#### Laravel 5.x\n Add to your config/app.php under Service Providers\n \u003cbr\u003e*(If you use Laravel 5.5+ you could skip this step as Autodiscovery has been enabled for this package.)*\n           \n ```\n //Service Providers\n danielme85\\Geoip2\\Geoip2ServiceProvider::class,\n //Facades\n 'Reader'  =\u003e danielme85\\Geoip2\\Facade\\Reader::class,\n \n ```\n \n#### Lumen 5.x\n Add to your boostrap/app.php file\n ```\n $app-\u003eregister(danielme85\\Geoip2\\Geoip2ServiceProvider::class);\n ...\n $app-\u003econfigure('app'); \n ...\n class_alias('danielme85\\Geoip2\\Facade\\Reader, 'Reader');\n $app-\u003ewithFacades();\n ```\n \n#### Config\n Publish the config file to your Laravel projects\n  ```\nphp artisan vendor:publish --provider=\"danielme85\\Geoip2\\Geoip2ServiceProvider\"\n  ```\n  The following default settings will work right away:\n  ```\n  return [\n      'geoip2' =\u003e [\n          'downloadUrl' =\u003e 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz', //url db file download\n          'tempFile' =\u003e 'app/GeoLite2-City.mmdb.gz', //temp download file name\n          'dbName' =\u003e 'app/GeoLite2-City.mmdb', //Geoip DB filename\n          'localhost' =\u003e '8.8.8.8' //when running on localhost (or for general testing) you can specify a fake ip address here.\n      ]\n  ];\n  ```\n \n### Usage\n You need to download the Maxmind Geoip first, the default config is for the city version (about 30MB download, 50MB extracted).\n ```\n php artisan geoip:download\n ```\n With the DB file downloaded you are ready to get some location data:\n ```\n use danielme85\\Geoip2\\Facade\\Reader;\n ...\n $reader = Reader::connect();\n $result = $reader-\u003ecity($ip);\n ```\n Usage once you have the Reader:connect object is the same as maxminds documentation\n https://github.com/maxmind/GeoIP2-php.\n \n Example usage, return json location data based on ipv4 address.\n ```php\n \u003c?php\n use danielme85\\Geoip2\\Facade\\Reader;\n ...\n \n function getLocation(Request $request) {\n    $reader = Reader::connect();\n    /*\n    I was experiencing inaccurate results... until I remembered that my web server traffic was routed trough CloudFlare :p\n    In that case CloudFlare provides the original client ip in the following header information.\n    */   \n    if (isset($_SERVER[\"HTTP_CF_CONNECTING_IP\"])) {\n        $ip = $_SERVER[\"HTTP_CF_CONNECTING_IP\"];\n    }\n    else {\n        $ip = $request-\u003eip();\n    }\n    //the city() function from the GeoIp2 Php API will throw an exception if the ip-address is not found in the DB.\n    try {\n        $geodata = $reader-\u003ecity($ip)-\u003ejsonSerialize(); //jsonSerialize seems to actually return an associative array.\n    }\n    catch (\\Exception $e) {\n        Log::warning($e-\u003egetMessage());\n        return response()-\u003ejson(\"Geo-location not found!\", 500);\n    }\n\n    return response()-\u003ejson($geodata);\n}\n ```\n\n\u003csmall\u003eThis product includes GeoLite2 data created by MaxMind, available from\n\u003ca href=\"http://www.maxmind.com\" target=\"_blank\"\u003ehttp://www.maxmind.com\u003c/a\u003e\u003c/small\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielme85%2Flaravel-geoip2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielme85%2Flaravel-geoip2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielme85%2Flaravel-geoip2/lists"}