Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Laravel 5.1. 5.2, 5.3, 5.4
'whitelist' => \Skydiver\LaravelRouteBlocker\Middleware\WhitelistMiddleware::class,
```

2. Create a config group on `config/laravel-route-blocker.php` and insert your allowed IPs:
2. Create a config group on `config/laravel-route-blocker.php` and insert your allowed IPs and controller/view to redirect to for denied IPs:
```
'whitelist' => [
'my_group' => [
Expand All @@ -49,6 +49,8 @@ Laravel 5.1. 5.2, 5.3, 5.4
'8.8.8.*'
],
],

'redirect_to' => '',
```

3. Put your protected routes inside a group and specify the whitelist parameter:
Expand Down
14 changes: 9 additions & 5 deletions src/Middleware/WhitelistMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ public function handle($request, Closure $next, $group) {
}
}
}

# THROW ERROR IF NOTHING FOUND
abort(config('laravel-route-blocker.response_status'), config('laravel-route-blocker.response_message'));


if(config('laravel-route-blocker.redirect_to')):
# REDIRECT TO CUSTOM ROUTE ASSIGNED IN THE CONFIG OPTIONS
return redirect()->to(config('laravel-route-blocker.redirect_to'));
else:
# THROW ERROR IF NOTHING FOUND
abort(config('laravel-route-blocker.response_status'), config('laravel-route-blocker.response_message'));
endif;
}

}

?>
?>
3 changes: 2 additions & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
],

# RESPONSE SETTINGS
'redirect_to' => '',
'response_status' => 403,
'response_message' => ''

];

?>
?>