PHP code example of hamidreza2005 / laravel-ip

1. Go to this page and download the library: Download hamidreza2005/laravel-ip library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hamidreza2005 / laravel-ip example snippets

  
    
    
return [    
   /*    
   |--------------------------------------------------------------------------    
   | Ip Driver    
   |--------------------------------------------------------------------------    
   |    
   | Here is where you can choose your driver for getting location from ip    
   | Supported :    
   |   "ipinfo" => visit https://www.ipinfo.io,    
   |   "ipapi" => visit https://www.ipapi.com,    
   |   "geojs" => visit https://www.geojs.io/    
   | Suggested : "geojs"    
   |    
   */  
    "ip_driver" => "geojs",    
   ...  
  ];  
  
     
return [   
   ...  
   "drivers" =>[    
     "ipinfo" =>[    
        "api_token" => 'YOUR_API_KEY'    
     ],    
     "ipapi" =>[    
        "api_token" => "YOUR_API_KEY"    
     ]    
 ]];  
  
use hamidreza2005\laravelIp\Facades\Ip;  
  
Route::get('/', function () {    
  return IP::countryCode();    
});  
  
IP::countryCode(); // return country Code e.g DE  
IP::all(); // return all Details about client's ip  
IP::coordinates(); // return client's coordinates  
IP::ip(); // return all client's ip  
IP::country(); // return all client's country full name e.g Germany
// Or you can use helper function
ip()->country();
ip("coountry"); // Both of them are true  

IP::all("8.8.8.8")


return [
	...
	"drivers" =>[  
        "ipinfo" =>[  
            "api_token" => "YOUR_API_TOKEN",  
            "full_country_name_path" => storage_path('default.json')  
		  ]
	 ],  
	 ...
];
  
protected $middleware = [    
   ...  
   \hamidreza2005\laravelIp\Middleware\laravelIp::class,  
   ...  
];  
  
  
return [  
   ...  
   "blocking"=>[    
        /*    
       * The values in this array won't access to website   
       */   
        "blacklist"=>[    
           "countryCode"=>["NK"],    
           "ip"=>["5.61.44.90"],  
           "coordinates" =>[[1.2.3.4,45.5.8.9]]    
       ],    
       /*    
       * only The values in this array can access to website   
       */  
       "whitelist"=>[    
//                  "countryCode"=>["US"]    
        ]    
    ]  
   ...  
];  
bash  
php artisan vendor:publish --tag=laravel-ip