title: Invalid argument supplied for foreach() in Laravel 8
body: <p>working with Laravel 8 and I have following view file with controller
  index.blade.php</p>
  <pre><code>&lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-md-12&quot;&gt;
          &lt;table class=&quot;table&quot;&gt;
              &lt;thead&gt;
                  &lt;th&gt;#&lt;/th&gt;
                  &lt;th&gt;Title&lt;/th&gt;
                  &lt;th&gt;Body&lt;/th&gt;
                  &lt;th&gt;Created At&lt;/th&gt;
                  &lt;th&gt;&lt;/th&gt;
              &lt;/thead&gt;
  
              &lt;tbody&gt;
                  @foreach ($posts ?? '' as $post)
  
                  &lt;tr&gt;
                      &lt;th&gt;{{$post-&gt;id}}&lt;/th&gt;
                      &lt;td&gt;{{$post-&gt;title}}&lt;/td&gt;
                      &lt;td&gt;{{ substr($post-&gt;body,0,50)}}{{ strlen($post-&gt;body) &gt; 50 ? &quot;...&quot; : &quot;&quot;}}&lt;/td&gt;
                      &lt;td&gt;{{ date('M j, Y', strtotime($post-&gt;created_at))}}&lt;/td&gt;
                      &lt;td&gt;&lt;a href=&quot;{{route('posts.show',$post-&gt;id)}}&quot; class=&quot;btn btn-default btn-sm&quot;&gt;View&lt;/a&gt;&lt;a href=&quot;{{route('posts.edit',$post-&gt;id)}}&quot; class=&quot;btn btn-default btn-sm&quot;&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                @endforeach
              &lt;/tbody&gt;
              
          &lt;/table&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  </code></pre>
  <p>and Controller</p>
  <pre><code>public function index()
      {
          $posts = Post::all();
          return view('posts.index');
      }
  
  </code></pre>
  <p>but I got following error message</p>
  <p><code>ErrorException Invalid argument supplied for foreach() (View: F:\2020 technologies\laravel\blog\resources\views\posts\index.blade.php) </code></p>
  <p>what is wrong with this. how could I fix this matter?</p>