ErrorException(E_WARNING)authManager.php laravel 6中的偏移量类型非法

时间:2019-11-09 17:37:43

标签: php laravel-6.2

我正在尝试为我的Laravel应用创建一个登录功能,该应用的寄存器正常运行,并且数据已添加到MySQL表中。但是当我使用凭据登录时,它显示了

  

ErrorException(E_WARNING)返回的偏移量类型非法   $ this-> guards [$ name]? $ this-> guards [$ name] = $ this-> resolve($ name);

请帮助我

public function guard($name = null)
{
    $name = $name ?: $this->getDefaultDriver();

    return $this->guards[$name] ?? $this->guards[$name] = $this->resolve($name);
}

我还添加了新的功能代码

public function guard($name = null)
{
    if (empty($name)) {
        $name = $this->getDefaultDriver();
    }
    echo 'Argument type: '. gettype($name);
    var_dump($name); 
    if (key_exists($name, $this->guards)) {
        $result = $this->guards[$name];
    } else {
        $result = $this->resolve($name);
    }
    return $result;
}

Now it is showing me this. 它显示在key_exists()中,第一个参数应该是整数或字符串,然后我添加了var_dump()方法以了解$ name的类型。

1 个答案:

答案 0 :(得分:0)

这对您有用吗?

public function guard($name = null)
{
    if (empty($name)) {
        $name = $this->getDefaultDriver();
    }

    if (key_exists($name, $this->guards)) {
        $result = $this->guards[$name];
    } else {
        $result = $this->resolve($name);
    }
    return $result;
}