Laravel 5.2:传递到视图的数据不起作用


Laravel 5.2: Data passed to the view not working

所以在我正在进行的这个Laravel项目中发生了一件非常奇怪的事情。我将一个带有数据的数组传递到我的刀片视图,但在视图中,变量显示为空!

这种情况只发生在直播服务器上,在我当地的流浪汉盒子上,一切都没问题。我不知道为什么会发生这种事,似乎也不明白。

我的控制器:

public function index()
{
    $this->view_data["representatives"] = array("Bruno", "Test", "Hey");
    return view("account.index")->with($this->view_data);
}

我的刀片视图:

@forelse($representatives as $representative)
    <p>{{ $representative }}</p>
@empty
    <p>There are no users yet!</p>
@endforelse

即使我做

print_r($representatives)

当我在本地正确获取数组时,它显示为空。

所以,就像我说的,奇怪的是,在本地,这对每个工作都很好,没有问题,并打印名称。

在服务器上时,它不起作用。

有趣的是,当在本地转储变量$representatives的内容时,我得到的数组没有问题,但在服务器上,它显示为

甚至不是找不到变量。这就像变量的内容被完全擦除了一样。

有什么想法吗?我整个上午都在做这个,到目前为止运气不好。再次感谢!

使用此

@forelse($representatives as $representative)
    <p>{{ $representative }}</p>
@empty
    <p>There are no users yet!</p>
@endforelse

试试这个

public function index()
{
    $this->view_data["representatives"] = array("Bruno", "Test", "Hey");
    return view("account.index")->with("representatives",$this->view_data);
}

试试这个

public function index()
{
    $this->view_data["representatives"] = array("Bruno", "Test", "Hey");
    return view("account.index",$this->view_data);
}