📜  laravel denny 通过 ip 请求 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:23.675000             🧑  作者: Mango

代码示例1
//Run:
//php artisan make:middleware IpMiddleware

ip() != "192.168.0.155") {
        // here instead of checking a single ip address we can do collection of ips
        //address in constant file and check with in_array function
            return redirect('home');
        }

        return $next($request);
    }

}
// END OF FILE

// ---------------------
// app/Http/Kernel.php
//then add the new middleware class in the $middleware property of your app/Http/Kernel.php class.

protected $routeMiddleware = [
    //... other middlewares
    'ipcheck' => \App\Http\Middleware\IpMiddleware::class,
];
// ------------------
///In your route
then apply middelware to routes

Route::get('/', ['middleware' => ['ipcheck'], function () {
    // your routes here
}]);