Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve all model data from a view in Laravel?
    primarykey
    data
    text
    <p>I'm trying to build a widget designing system where a user can submit the title and html of the widget.Now when I try query the Widget model in a view and pass the data to <code>@foreach</code> loop,I get the error as <code>@foreach</code> is not able to iterate over the queryset returned by <code>Widget::all()</code>.How can I display all the data from Widget model on my webpage?</p> <p>Btw my Widget model has only two fields(i.e title and html).</p> <p>EDIT:Following is the <code>var_dump</code> of what I get in return when I do <code>Widget::all()</code></p> <pre><code>array(2) { [0]=&gt; object(Widget)#42 (5) { ["attributes"]=&gt; array(3) { ["id"]=&gt; string(1) "1" ["title"]=&gt; string(24) "Join Demo classes today!" ["html"]=&gt; string(47) " This is just the great demo of widgets. " } ["original"]=&gt; array(3) { ["id"]=&gt; string(1) "1" ["title"]=&gt; string(24) "Join Demo classes today!" ["html"]=&gt; string(47) " This is just the great demo of widgets. " } ["relationships"]=&gt; array(0) { } ["exists"]=&gt; bool(true) ["includes"]=&gt; array(0) { } } [1]=&gt; object(Widget)#45 (5) { ["attributes"]=&gt; array(3) { ["id"]=&gt; string(1) "2" ["title"]=&gt; string(12) "About Google" ["html"]=&gt; string(66) "Google is the best site in the world." } ["original"]=&gt; array(3) { ["id"]=&gt; string(1) "2" ["title"]=&gt; string(12) "About Google" ["html"]=&gt; string(66) "Google is the best site in the world." } ["relationships"]=&gt; array(0) { } ["exists"]=&gt; bool(true) ["includes"]=&gt; array(0) { } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload