diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..972cfe6 --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "ilhamdev/ipwhitelist", + "description": "Simple Ip White List", + "license": "MIT", + "authors": [ + { + "name": "M Ilham Sabar", + "email": "ilhamsabar@gmail.com" + } + ], + "autoload": { + "psr-4": { + "ilhamdev\\ipwhitelist\\" : "src" + } + }, + "require": {} +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e297712 --- /dev/null +++ b/readme.md @@ -0,0 +1,19 @@ +## 👽 Simple IP White List + +## How To Install + composer require ilhamdev/ipwhitelist + +## How To Use +### Add This Package in app/Http/Kernel.php + protected $routeMiddleware = [ + 'ipwhitelist' => \ilhamdev\ipwhitelist\middleware\CheckIpMiddleware::class, + ]; + +### In Your .env add your Ip + APP_IP_WHITELIST=127.0.0.1,192.168.1.1 + +### In Your Controller + public function __construct() + { + $this->middleware('ipwhitelist'); + } diff --git a/src/middleware/CheckIpMiddleware.php b/src/middleware/CheckIpMiddleware.php new file mode 100644 index 0000000..f5f08ad --- /dev/null +++ b/src/middleware/CheckIpMiddleware.php @@ -0,0 +1,23 @@ +ip(), explode(',',env('APP_IP_WHITELIST')))) { + return response('Access Denied',500); + } + + return $next($request); + } +} \ No newline at end of file