Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
ilham-dev committed Oct 30, 2020
0 parents commit dea4e0b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
19 changes: 19 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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');
}
23 changes: 23 additions & 0 deletions src/middleware/CheckIpMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace ilhamdev\ipwhitelist\middleware;
use Closure;

class CheckIpMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!in_array($request->ip(), explode(',',env('APP_IP_WHITELIST')))) {
return response('Access Denied',500);
}

return $next($request);
}
}

0 comments on commit dea4e0b

Please sign in to comment.