Laravel IP Whitelist is a package contain middleware to allow a list of IP addresses to access a specific web resource.
You can install the package via composer:
composer require alitindrawan24/laravel-ip-whitelist
You can publish the config file with:
php artisan vendor:publish --provider="Alitindrawan24\IPWhitelist\IPWhitelistServiceProvider" --tag="config"
By default the IP Whitelist feature is disabled, to enable the feature you add this in your .env
IP_WHITELIST_ENABLE=true
You can add the list of IP that allowed in config/ip-whitelist.php using fix IP or using wildcard
/**
* List of IP Whitelist.
* Only IP in this list is allowed to pass the middleware.
*/
'ip_whitelist' => [
// '127.0.0.1' // Localhost example
// '127.0.0.*' // Using Wildcard example
],
This packages provides a middleware which can be added as a global middleware or as a single route.
// in `app/Http/Kernel.php`
protected $middleware = [
// ...
\Alitindrawan24\IPWhitelist\Middleware\HttpLogger::class
];
// in a routes file
Route::post('/dashboard', function () {
//
})->middleware(\Alitindrawan24\IPWhitelist\Middleware\HttpLogger::class);
This project is licensed under the MIT License - see the LICENSE.md file for details.