yish / laravel-accessible-ip
Accessible IPs for Laravel.
Installs: 1 519
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.4
- illuminate/contracts: 5.1.*|5.2.*|5.3.*|5.4.*
- illuminate/support: 5.1.*|5.2.*|5.3.*|5.4.*
- mockery/mockery: ^0.9.9
- phpunit/phpunit: 5.7.*
Requires (Dev)
- laravel/laravel: 5.2.*|5.3.*|5.4.*
README
Accessible IPs for Laravel. Supported allowed ip and proxy server.
Requirement
laravel 5.1 - 5.4.
Installation
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'); }); });
Exception
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.