0
所以我有一个与artisan make:auth
生成的登录区域,这已经创建了&控制器正确的意见,并已将Route::auth();
添加到我的routes.php ..一切都很好,但现在我想限制登录到一个IP列表。Laravel将自定义中间件添加到Route :: auth();
我已经创建了一个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();
});
这工作我的本地虚拟机上,但只要其在活的服务器上,收到了错误:达到“100”
最大函数嵌套层次,中止!
我通过增加xdebug.max_nesting_level
来找到解决方法,但这不能解决代码中的问题。
任何想法?谢谢。