在 $request->ip() 上,我在本地主机上得到“::1”,我的控制器无法使用白名单 IP 给我自定义错误

On $request->ip() I get "::1" on localhost and my controller does not work with white list IP give me custom error

我有一个控制器,应该允许为一个 IP 使用资源。如果 IP 是无效控制器,则应给出自定义错误“不正确的 IP”。 但是在执行控制器时,我不断收到自定义错误“IP 不正确”。 当我发送 $request->ip() 我得到“::1” 我正在使用本地主机 我的控制器

class OhDayHiepController extends Controller
{
   const ALLOWED = [
       "5.5.5.5",
    ];
    public function whiteIP (Request $request)
    {
        abort_unless(in_array($request->ip(), self::ALLOWED), die("Not correct IP"));
        return $request;
    } 
}

为什么我的错误以及为什么我得到 ::1。也许因为 localhost 需要自定义

"::1" 代表 IPv6 中的“localhost”。您似乎在使用 IPv4 (xxx.xxx.xxx.xxx)。

我不知道你想要达到什么目的,所以我不能肯定地给你解决方案,但你可以尝试使用 "::1" 而不是 "5.5.5.5" in ALLOWED.

还必须有一种方法可以将您的本地服务器配置为仅使用 IPv4。