This blog's main objective is to build a functionality that can restrict or block users to access websites based on particular IP addresses.
Let's assume you already have a working Laravel application. If not create a fresh Laravel application and configure the database.
To restrict users based on the IP address we need to check every request coming from the user. We can do that by middleware in Laravel.
Create Restrict IP Middleware
In Laravel, middleware is a filtering mechanism that filters requests and responses. For creating middleware open the terminal and enter the following command :
php artisan make:middleware RestrictIpAddress
This command will create a new file at App\Http\Controllers\RestrictIpAddress.php. Practically we will write all logic for IP Restriction into this file. So make the below changes :