Accessible IPs for Laravel. Supported allowed ip and proxy server.
Install via composer
$ composer require yish/laravel-accessible-ip
You need to register service provider in config/app.php
, also, you can binding AppServiceProvider
on register.
Notice
You must register provider after Illuminate\Http\Request
.
'providers' => [
...
/*
* Package Service Providers...
*/
Mombuyish\AccessibleIP\AccessibleIPServiceProvider::class,
...
Next, navigate to app/Http/Middleware/Kernel.php
, adding middleware
protected $routeMiddleware = [
'access-ip' => \Mombuyish\AccessibleIP\Middleware\AccessibleIPAddress::class,
];
Finally, publish the config.
$ php artisan vendor:publish --provider="Mombuyish\AccessibleIP\AccessibleIPServiceProvider"
You can configrate on config access-ip.php
🎉🎉 Supported CI/DR !! 🎉🎉
Including 127.0.0.1
inside, so you don't need add it.
'allowed' => [
'123.11.22.33',
'123.11.0.0/32'
],
If you have proxies server on front, you should be place proxies:
🎉🎉 Supported CI/DR !! 🎉🎉
'proxies' => [
env('PROXY_SERVER_IP'),
'123.11.0.0/32'
],
You can use on routing middleware, for example:
Route::get('/', function () {
return view('welcome');
})->middleware('access-ip');
or you can do this:
Route::group(['middleware' => ['access-ip']], function() {
Route::get('/', function () {
return view('welcome');
});
});
When you denied by middleware, you will get 403 Forbidden
.
You can use app/Exceptions/Handler.php
to change exception do something.
It will get same things.