所以我有一个登录区域,它是用artisan make:auth
生成的,它正确地创建了视图和控制器,并将Route::auth();
添加到我的路由中.php..一切都很好,但现在我想将登录限制为IP列表。
我创建了一个 IPRestrictions 中间件,并在内核中引用了.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();
});
这适用于我的本地虚拟机,但一旦它在实时服务器上,我就会收到错误:
达到最大函数嵌套级别"100",正在中止!
我已经通过增加xdebug.max_nesting_level
找到了解决方法,但这并不能解决代码中的问题。
有什么想法吗?谢谢。
在bootstrap/autoload.php
文件中添加以下行:
ini_set('xdebug.max_nesting_level', 200);