我正在尝试构建一个小部件设计系统,用户可以在其中提交小部件的标题和 html。现在,当我尝试在视图中查询小部件模型并将数据传递给@foreach
循环时,我收到错误,因为@foreach
无法遍历返回的查询集。Widget::all()
如何在我的网页上显示来自 Widget 模型的所有数据?
顺便说一句,我的 Widget 模型只有两个字段(即标题和 html)。
编辑:以下是var_dump
我这样做时得到的回报Widget::all()
array(2) { [0]=> object(Widget)#42 (5) { ["attributes"]=> array(3) { ["id"]=> string(1) "1" ["title"]=> string(24) "Join Demo classes today!" ["html"]=> string(47) "
This is just the great demo of widgets.
" } ["original"]=> array(3) { ["id"]=> string(1) "1" ["title"]=> string(24) "Join Demo classes today!" ["html"]=> string(47) "
This is just the great demo of widgets.
" } ["relationships"]=> array(0) { } ["exists"]=> bool(true) ["includes"]=> array(0) { } } [1]=> object(Widget)#45 (5) { ["attributes"]=> array(3) { ["id"]=> string(1) "2" ["title"]=> string(12) "About Google" ["html"]=> string(66) "Google is the best site in the world." } ["original"]=> array(3) { ["id"]=> string(1) "2" ["title"]=> string(12) "About Google" ["html"]=> string(66) "Google is the best site in the world." } ["relationships"]=> array(0) { } ["exists"]=> bool(true) ["includes"]=> array(0) { } } }