Skip to content

Commit 7a91303

Browse files
committed
readme usage example update
1 parent 67f3860 commit 7a91303

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

README.md

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
![Abuse Ip](https://github.com/user-attachments/assets/ff47c6b4-297f-4984-ae5d-1829b61bd4c6)
22

3-
43
# Laravel Abuse-IP
54

65
##Keep you webiste safe from spammer.
76

87
![Packagist Downloads](https://img.shields.io/packagist/dt/rahulalam31/Laravel-Abuse-IP) ![Packagist Version](https://img.shields.io/packagist/v/rahulalam31/Laravel-Abuse-IP) [![License: MIT](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/license/mit) [![Update SPAM IP List](https://github.com/rahulalam31/Laravel-Abuse-IP/actions/workflows/update_spamiplist.yml/badge.svg)](https://github.com/rahulalam31/Laravel-Abuse-IP/actions/workflows/update_spamiplist.yml)
98

10-
11-
Adds a Security to Laravel for checking whether the IP address is safe or marked as spam to keep you out of worry from spammers and fake data to your website.
9+
Adds a Security to Laravel for checking whether the IP address is safe or marked as spam to keep you out of worry from spammers and fake data to your website.
1210
Uses the AbuseIPDB blocklist from [borestad/blocklist-abuseipdb](https://github.com/borestad/blocklist-abuseipdb) by default.
1311

1412
### Installation
1513

1614
1. Run the Composer require command to install the package. The service provider is discovered automatically.
1715

1816
```bash
19-
composer require rahulalam31/laravel-abuse-ip
17+
composer require rahulalam31/laravel-abuse-ip
2018
```
2119

2220
2. Publish the configuration file and adapt the configuration as desired:
@@ -26,35 +24,37 @@ Uses the AbuseIPDB blocklist from [borestad/blocklist-abuseipdb](https://github.
2624
```
2725

2826
3. Run the following artisan command to fetch an up-to-date list of disposable domains:
29-
27+
3028
```bash
3129
php artisan abuseip:update
3230
```
3331

34-
3.1. Add the following to you ```.env``` file.
35-
Add ```ABUSEIP_STORAGE_PATH``` to change your storage location,
36-
Add ```ABUSEIP_STORAGE_COMPRESS``` ```true/false``` to enable or disable ```ip2long()```
32+
3.1. Add the following to you `.env` file.
33+
Add `ABUSEIP_STORAGE_PATH` to change your storage location,
34+
Add `ABUSEIP_STORAGE_COMPRESS` `true/false` to enable or disable `ip2long()`
3735
36+
4. (optional) It's highly advised to update the AbuseIp list daily as the spam ip address keeps changing daily, but you can schedule it as per your need regularly. You can either run the command yourself now and then or, if you make use of Laravel's scheduler, you can register the `abuseip:update` command:
3837
39-
4. (optional) It's highly advised to update the AbuseIp list daily as the spam ip address keeps changing daily, but you can schedule it as per your need regularly. You can either run the command yourself now and then or, if you make use of Laravel's scheduler, you can register the `abuseip:update` command:
38+
In `routes/console.php`:
4039
41-
In `routes/console.php`:
4240
```php
4341
use Illuminate\Support\Facades\Schedule;
44-
//
42+
//
4543
Schedule::command('abuseip:update')->daily();
4644
```
4745

4846
Or if you use Laravel 10 or below, head over to the Console kernel:
49-
```php
50-
protected function schedule(Schedule $schedule)
51-
{
52-
$schedule->command('abuseip:update')->daily();
53-
}
47+
48+
```php
49+
protected function schedule(Schedule $schedule)
50+
{
51+
$schedule->command('abuseip:update')->daily();
52+
}
5453
```
54+
5555
### Usage
5656

57-
Use the `middleware::AbuseIp::class` where ever required like in form page or post urls.Or you can add the middleware to your code, For Laravel 10 and below add the middleware `Http/Kernel.php`, For Laravel 11 add to `bootstrap/app/php`
57+
Use the `middleware::AbuseIp::class` where ever required like in form page or post urls.Or you can add the middleware to your code, For Laravel 10 and below add the middleware `Http/Kernel.php`, For Laravel 11 add to `bootstrap/app/php`
5858

5959
```php
6060
//Laravel 10 and below
@@ -63,25 +63,55 @@ Use the `middleware::AbuseIp::class` where ever required like in form page or po
6363
*/
6464
6565
protected $middleware = [
66-
\App\Http\Middleware\AbuseIp::class,
66+
\RahulAlam31\LaravelAbuseIp\Middleware\AbuseIp::class,
6767
.....
6868
]
6969
7070
7171
```
7272

73-
7473
```php
7574
//Laravel 11
7675
/*
7776
* bootstrap/app.php
7877
*/
7978
->withMiddleware(function (Middleware $middleware) {
80-
$middleware->append(\App\Http\Middleware\AbuseIp::class);
79+
$middleware->append(\RahulAlam31\LaravelAbuseIp\Middleware\AbuseIp::class);
8180
})
8281
8382
```
8483

84+
If you don't want to put it in your route middleware you can make a `aliasMiddleware()` and use the alias in your routes file to disable spam ip visits.
85+
86+
```php
87+
//Laravel 10 and below
88+
/*
89+
* app/Http/Kernel.php
90+
*/
91+
92+
protected $routeMiddleware = [
93+
.....,
94+
'abuseip' => \RahulAlam31\LaravelAbuseIp\Middleware\AbuseIp::class,
95+
96+
]
97+
98+
Route::get('/xyz', function () {
99+
//
100+
})->middleware('abuseip');
101+
```
102+
103+
```php
104+
//Laravel 11
105+
/*
106+
* bootstrap/app.php
107+
*/
108+
109+
->withMiddleware(function (Middleware $middleware) {
110+
//
111+
})
112+
->aliasMiddleware('abuse_ip', \RahulAlam31\LaravelAbuseIp\Middleware\AbuseIp::class)
113+
114+
```
85115
86116
```php
87117
// Or use in route file

0 commit comments

Comments
 (0)