Laravel 将数组传递给刀片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27943936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:41:37 来源:igfitidea点击:
Laravel passing an array to blade
提问by LeBlaireau
Trying to use this,
尝试使用这个,
return View::make('products.tables')->with('json', $json);
but get an Array to string conversion error.
但得到一个数组到字符串转换错误。
json array
json数组
$json = array (
"item1" => "no1",
"item2" => "no2",
"item3" => "no3",
);
采纳答案by Tomas Turan
It means that in your view you are calling array items wrong way.
这意味着在您看来,您以错误的方式调用数组项。
It should be like this:
应该是这样的:
$json->item1
Or:
或者:
@foreach($json as $item)
{{ $item }}
@endforeach
回答by Nicola Pulvirenti
Try this:
尝试这个:
$json = array (
"item1" => "no1",
"item2" => "no2",
"item3" => "no3",
);
$data = array (
'json' => $json
);
return View::make('products.tables')->with($data)
and then, in your view:
然后,在您看来:
@foreach($json as $item)
{{ $item }}
@endforeach
This should work.
这应该有效。