Laravel package for providing restricted access by IP Address to your application
hayrican/ipchecker is a Laravel package for laravel package for providing restricted access by ip address to your application.
It currently has 27 GitHub stars and 898 downloads on Packagist (latest version v1.3.0).
Install it with composer require hayrican/ipchecker.
Discover more Laravel packages by hayrican
or browse all Laravel packages to compare alternatives.
Last updated
This package provides restricted access via IP Address to your application.
To get started, you should add the hayrican/ipchecker Composer dependency to your project:
composer require hayrican/ipchecker
Register provider on your config/app.php file.
'providers' => [
...,
HayriCan\IpChecker\IpCheckerServiceProvider::class,
]
You should publish vendor for configuration file.
$ php artisan vendor:publish --tag="ipchecker"
The config file is called ipchecker.php. Currently supported drivers are db and file
Default driver is file and ipchecker will use file to record ip addresses. But if you want to use Database for records, migrate table by using
php artisan migrate
You have to change driver to db before migrate. Otherwise it will not migrate the table.
'api_middleware'=>'api',
'web_middleware'=>'web',
If your routes has different middleware then these default values you can change them in here. These route middleware need for filtering response of denial access.
When you call php artisan vendor:publish --tag="ipchecker" command, it will also publish lang file to your resources/lang directory. You can change all fields as you desire.
Add middleware named ipchecker to the route or controller you want to log data
// in app.php or web.php
Route::group(['middleware' => ['ipchecker']], function () {
Route::get('test',function (){
dd('Test API');
});
});
When try to access this route it will check your IP Address. If you ip address is not on the list you will get response
{
"success": false,
"code": 250,
"message": "Your IP Address not in the list."
}
Otherwise you will access to the route.
Up to default config dashboard can be accessible via yourdomain.com/iplists but it is configurable from config file ipchecker.php
{
"settings"=>[
"auth" => false,
"admin_id"=>[],
"route_prefix"=> "",
],
}
If you want to guard this page just change "auth" to true and it require "auth" middleware.
When you enabled auth you could add admin users id to "admin_id" array.
If leave "admin_id" array empty, all users can has access to IP Checker dashboard
{
"settings"=>[
"auth"=> true,
"admin_id"=>[2,5],
"route_prefix"=> "",
],
}
Also you can change the route prefix of this dashboard. If you change "route_prefix" to "foo" your dashboard will be accessible via yourdomain.com/foo/iplists.
You can add IP Address in here.
Hayri Can BARÇIN
Email: Contact Me
This project is licensed under the MIT License - see the License File for details