Laravel 5.2:传递给视图的数据不起作用
Laravel 5.2: Data passed to the view not working
所以我正在处理的这个 Laravel 项目中发生了一件非常奇怪的事情。
我将一个包含数据的数组传递到我的 blade 视图,但是在视图中时变量显示为空!
这只发生在实时服务器上,在我的本地 homestead vagrant box 上一切正常。我不知道为什么会这样,而且似乎无法弄清楚。
我的控制器:
public function index()
{
$this->view_data["representatives"] = array("Bruno", "Test", "Hey");
return view("account.index")->with($this->view_data);
}
我的 Blade 查看:
@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);
}
所以我正在处理的这个 Laravel 项目中发生了一件非常奇怪的事情。 我将一个包含数据的数组传递到我的 blade 视图,但是在视图中时变量显示为空!
这只发生在实时服务器上,在我的本地 homestead vagrant box 上一切正常。我不知道为什么会这样,而且似乎无法弄清楚。
我的控制器:
public function index()
{
$this->view_data["representatives"] = array("Bruno", "Test", "Hey");
return view("account.index")->with($this->view_data);
}
我的 Blade 查看:
@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);
}