我得到了非法的偏移类型。在供应商\ laravel ramework \ src \ Illuminate \ Routing \ RouteCollection.php:127

问题描述 投票:0回答:1

非法偏移类型

无论我的命令是什么,它仍然显示为这样。 错误

我会尝试使用 chatgpt 中的以下代码。但没有任何改变。我完全是个初学者,完全不知道

use Illuminate\Support\Facades\Log;

public function refreshNameLookups()
{
    $this->nameList = [];

    foreach ($this->allRoutes as $route) {
        if ($route->getName()) {
            $name = $route->getName();
            // Log the type of the route name
            Log::info('Route name type: ' . gettype($name));
            $this->nameList[$name] = $route;
        }
    }
}

我也在Youtube上搜索过,但似乎没有问题和我的一样。

laravel laragon
1个回答
0
投票

PHP 错误“TypeError:非法偏移类型”意味着您试图错误地引用数组索引。在这种情况下,

$name
包含一个不能用作数组索引的值(即,一个对象、另一个数组等)。由于
$name
$route->getName()
的结果,请查看
getName()
\Illuminate\Routing\Route

公共函数 getName()
{
返回 $this->action['as'] ??空;
}

我会看一下你定义的路由(例如,在你的routes/web.php文件中),问题大多在那里。

© www.soinside.com 2019 - 2024. All rights reserved.