This is an annoying IP management package for Laravel that you can use in your projects.
Run the following command to pull in the latest version:
composer require jobmetric/laravel-ban-ipsTo use the services of this package, please follow the instructions below.
After installing the package, you must migrate by running the following command:
php artisan migrateTo use the services of this package, you must use the BanIp class in your model.
To store a ban ip, you can use the following code:
use JobMetric\BanIp\Facades\BanIp;
BanIp::store([
'ip' => 'sample ip',
'type' => 'hacker',
'reason' => 'This is a sample reason',
'banned_at' => now(),
'expire_at' => now()->addDays(1),
]);Note:
The
ipfield is required and must be a string.The
typefield is required and must be one of the following values:hacker,spammer,bot,another.The
reasonfield is required and must be a string.The
banned_atfield is required and must be a date.The
expire_atfield is required and must be a date greater than thebanned_atfield.
To update a ban ip, you can use the following code:
use JobMetric\BanIp\Facades\BanIp;
BanIp::update([
'type' => 'hacker',
'reason' => 'This is a sample reason',
'banned_at' => now(),
'expire_at' => now()->addDays(1),
]);Note:
The
typefield is sometimes and must be one of the following values:hacker,spammer,bot,another.The
reasonfield is sometimes and must be a string.The
banned_atfield is sometimes and must be a date.The
expire_atfield is sometimes and must be a date greater than thebanned_atfield.
To delete a ban ip, you can use the following code:
use JobMetric\BanIp\Facades\BanIp;
BanIp::delete(/* ban ip id */);To delete expired ban ip, you can use the following code:
use JobMetric\BanIp\Facades\BanIp;
BanIp::deleteExpired();This package contains several helper functions that you can use as follows:
storeBanIp: This function is used to store a ban ip.updateBanIp: This function is used to update a ban ip.deleteBanIp: This function is used to delete a ban ip.deleteExpiredBanIp: This function is used to delete expired ban ip.
There are some rules for using this package:
BanIpExistRule: This rule is used to check if the IP is banned.
There can be various reasons for the IP ban:
hacker: This type of ban is used for hackers.spammer: This type of ban is used for spammers.bot: This type of ban is used for bots.another: This type of ban is used for other reasons.
This package contains several commands that you can use as follows
| Command | Description |
|---|---|
ban-ip:remove |
Remove ban ip expire time. (This command is executed every minute in your Laravel) |
This package contains several events for which you can write a listener as follows
| Event | Description |
|---|---|
BanIpStoredEvent |
This event is called after storing the ban ip. |
BanIpUpdateEvent |
This event is called after updating the ban ip. |
BanIpDeleteEvent |
This event is called after delete the ban ip. |
Thank you for considering contributing to the Laravel Ban Ip! The contribution guide can be found in the CONTRIBUTING.md.
The MIT License (MIT). Please see License File for more information.