PHP code example of orkhanahmadov / laravel-ip-middleware

1. Go to this page and download the library: Download orkhanahmadov/laravel-ip-middleware library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

orkhanahmadov / laravel-ip-middleware example snippets


protected $routeMiddleware = [
    // ...
    'ip_whitelist' => \Orkhanahmadov\LaravelIpMiddleware\WhitelistMiddleware::class,
    'ip_blacklist' => \Orkhanahmadov\LaravelIpMiddleware\BlacklistMiddleware::class,
];

Route::middleware('ip_whitelist:1.1.1.1')->get('/', 'HomeController@index');
Route::middleware('ip_blacklist:3.3.3.3')->get('/', 'PostController@index');

Route::middleware('ip_whitelist:1.1.1.1,2.2.2.2')->get('/', 'HomeController@index');

// config/ip-middleware.php

'predefined_lists' = [
    'my-list-1' => ['1.1.1.1', '2.2.2.2'],
    'my-list-2' => ['3.3.3.3', '4.4.4.4'],
];

Route::middleware('ip_whitelist:my-list-1,my-list-2')->get('/', 'HomeController@index');
// you can also mix predefined list with additional IP addresses
Route::middleware('ip_whitelist:my-list-1,my-list-2,5.5.5.5,6.6.6.6')->get('/', 'PostController@index');
bash
php artisan vendor:publish --provider="Orkhanahmadov\LaravelIpMiddleware\LaravelIpMiddlewareServiceProvider"