Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel向Route::auth()添加自定义中间件;_Php_Laravel_Authentication_Routing_Middleware - Fatal编程技术网

Php Laravel向Route::auth()添加自定义中间件;

Php Laravel向Route::auth()添加自定义中间件;,php,laravel,authentication,routing,middleware,Php,Laravel,Authentication,Routing,Middleware,因此,我有一个登录区域,它是使用artisan make:auth生成的,它正确地创建了视图和控制器,并添加了Route::auth()到my routes.php。。一切都很好,但现在我想限制登录IP列表 我已经创建了一个IPRestrictions中间件,并在Kernel.php中引用了它 中间件代码: namespace App\Http\Middleware; use Closure; class IPRestrictions { public function handl

因此,我有一个登录区域,它是使用
artisan make:auth
生成的,它正确地创建了视图和控制器,并添加了
Route::auth()到my routes.php。。一切都很好,但现在我想限制登录IP列表

我已经创建了一个IPRestrictions中间件,并在Kernel.php中引用了它

中间件代码:

namespace App\Http\Middleware;

use Closure;

class IPRestrictions {

    public function handle($request, Closure $next) {

        // Allowed IPs
        $allowed = ['xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx'];

        // Get the IP address
        $ip = $request->ip();

        // Check if the ip is valid or if allowed
        if (!filter_var($ip, FILTER_VALIDATE_IP) || !in_array($ip, $allowed)) return abort(404);

        return $next($request);
    }
}
内核:

'restrict-ips' => \App\Http\Middleware\IPRestrictions::class
我已尝试将此中间件应用于如下路由:

Route::group(['middleware' => 'restrict-ips'], function() {
    Route::auth();
});
这可以在我的本地虚拟机上运行,但一旦在live server上运行,我就会收到错误:

已达到最大函数嵌套级别“100”,正在中止

我通过增加
xdebug.max\u nesting\u级别找到了解决办法,但这并不能解决代码中的问题


有什么想法吗?谢谢。

在您的
引导/autoload.php
文件中添加以下行:

ini_set('xdebug.max_nesting_level', 200);