Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ErrorException:未定义索引:数据位于../app/Widgets/TopMenu.php:23_Php_Laravel_Web_Laravel 5 - Fatal编程技术网

ErrorException:未定义索引:数据位于../app/Widgets/TopMenu.php:23

ErrorException:未定义索引:数据位于../app/Widgets/TopMenu.php:23,php,laravel,web,laravel-5,Php,Laravel,Web,Laravel 5,更新:问题已解决 我在第26行出现了一个错误,说明了未定义的索引“data”,我尝试在顶部使用isset,但没有任何效果。非常感谢您的帮助 class TopMenu extends AbstractWidget { /** * Treat this method as a controller action. * Return view() or other content to display. */ public function ru

更新:问题已解决

我在第26行出现了一个错误,说明了未定义的索引“data”,我尝试在顶部使用isset,但没有任何效果。非常感谢您的帮助

    class TopMenu extends AbstractWidget {
    /**
     * Treat this method as a controller action.
     * Return view() or other content to display.
     */
    public function run()
    {

       $SDKInstance = new BlackLabelSdk();
       $listFilter = $SDKInstance->getFilterList();
       
    return view("widgets.top_menu", [
            'categories' => Categorymodel::archives(),
            'blacklabelFilter' => $listFilter['data']['categories']
    ]);
    
    }
}
编辑:

这是我的黑标签

这就是我的观点

<body>
<?php echo app('arrilot.widget')->run('TopMenu'); ?>

在返回视图()之前,请确保数据可用。

$listFilter = $SDKInstance->getFilterList();

$result = null;
if (isset($listFilter['errors'])){
     // do something with the errors
   $result = // store the errors and present them in the view or something
} 
else
{
    // all good so here you should have `$listFilter['data']` available.
   $result = $listFilter['data']['categories'];
}
       
return view("widgets.top_menu", [
       'categories' => Categorymodel::archives(),
       'blacklabelFilter' => $result
]);

$listFilter
的值是多少?你能在上面使用
dd()
吗?因为我认为这个错误是因为你正在访问
$listFilter
数据
索引,这个索引可能不存在。这是我在dd($listFilter)时得到的;阵列:2[▼ “错误”=>数组:1[▶] “sessionId”=>“max age=0,没有缓存,没有存储,必须重新验证,post-check=0,pre-check=0”]什么是
$SDKInstance->getFilterList();
do?显然错误就在这里$listFilter['data'],那么为什么isset()没有帮助呢?您是如何使用它的?尝试使用dd($listFilter)转储过滤器中的内容只要变量也是数组,就可以看到数组中是否有“data”项。
$listFilter = $SDKInstance->getFilterList();

$result = null;
if (isset($listFilter['errors'])){
     // do something with the errors
   $result = // store the errors and present them in the view or something
} 
else
{
    // all good so here you should have `$listFilter['data']` available.
   $result = $listFilter['data']['categories'];
}
       
return view("widgets.top_menu", [
       'categories' => Categorymodel::archives(),
       'blacklabelFilter' => $result
]);