title: Trying to read from a database using laravel
body: <p><br>
  I am trying to create a blog using Laravel 5.5 but I have received this error. </p>
  
  <pre><code>"Missing required parameters for [Route: posts.show] [URI: posts/{post}]. (View: /home/vagrant/Code/dialhousesetup.test/resources/views/posts/index.blade.php)"
  </code></pre>
  
  <p>On my postcontroller.php file. I did this so I can output all posts on my database:</p>
  
  <pre><code>public function index()
      {
          //Create a variable and store all the blog posts in it from the data base
          $posts = Post::all();
  
          //Return a view and pass in the above variable
          return view('posts.index', array('posts' =&gt; $posts));
      }
  </code></pre>
  
  <p>This is the loop I wrote on the /posts page to display all the blog posts.</p>
  
  <pre><code>&lt;div class="events mb-100"&gt;
          &lt;div class="container"&gt;
              &lt;div class="row"&gt;
                 @foreach ($posts as $post)
                  &lt;div class="col-md-6"&gt;
                     &lt;a href="{{ route('posts.show'), $post-&gt;id }}"&gt;
                      &lt;div class="single-event text-center"&gt;
                          &lt;img src="http://www.dialhousehotel.com/wp-content/uploads/2018/01/CC_1419-The-Dial-House-website-01-18-04.jpg" alt="" style="border:2px solid #bb9b50;"&gt;
                          &lt;h2&gt;{{$post-&gt;title}}&lt;/h2&gt;
                          &lt;p&gt;{{$post-&gt;main_body}}&lt;/p&gt;
                          &lt;div class="separator"&gt;&lt;/div&gt;
                          &lt;a href="{{ route('posts.show'), $post-&gt;id }}"&gt;&lt;button type="submit" class="button button-simple mt-30"&gt;Read More&lt;/button&gt;&lt;/a&gt;
                      &lt;/div&gt;
                      &lt;/a&gt;
                  &lt;/div&gt;
                @endforeach
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I honestly don't know what I did wrong.</p>
  
  <p>Update:
  People have noticed there was a syntax issue and I have replaced {{ route('posts.show'), $post->id }} with {{ route('posts.show', $post->id) }}</p>
  
  <pre><code>@foreach($posts as $post)
                  &lt;div class="col-md-6"&gt;
                     &lt;a href="{{ route('posts.show', $post-&gt;id) }}"&gt;
                      &lt;div class="single-event text-center"&gt;
                          &lt;img src="http://www.dialhousehotel.com/wp-content/uploads/2018/01/CC_1419-The-Dial-House-website-01-18-04.jpg" alt="" style="border:2px solid #bb9b50;"&gt;
                          &lt;h2&gt;{{$post-&gt;title}}&lt;/h2&gt;
                          &lt;p&gt;{{$post-&gt;main_body}}&lt;/p&gt;
                          &lt;div class="separator"&gt;&lt;/div&gt;
                          &lt;a href="{{ route('posts.show', $post-&gt;id) }}"&gt;&lt;button type="submit" class="button button-simple mt-30"&gt;Read More&lt;/button&gt;&lt;/a&gt;
                      &lt;/div&gt;
                      &lt;/a&gt;
                  &lt;/div&gt;
                @endforeach
  </code></pre>
  
  <p>However, I am now getting an <code>"Invalid argument supplied for foreach() (View: /home/vagrant/Code/dialhousesetup.test/resources/views/posts/index.blade.php)"</code></p>
  
  <pre><code>&lt;?php $__currentLoopData = $posts; $__env-&gt;addLoop($__currentLoopData); foreach($__currentLoopData as $post): $__env-&gt;incrementLoopIndices(); $loop = $__env-&gt;getLastLoop(); ?&gt;
                  &lt;div class="col-md-6"&gt;
                     &lt;a href="&lt;?php echo e(route('posts.show', $post-&gt;id)); ?&gt;"&gt;
                      &lt;div class="single-event text-center"&gt;
                          &lt;img src="http://www.dialhousehotel.com/wp-content/uploads/2018/01/CC_1419-The-Dial-House-website-01-18-04.jpg" alt="" style="border:2px solid #bb9b50;"&gt;
                          &lt;h2&gt;&lt;?php echo e($post-&gt;title); ?&gt;&lt;/h2&gt;
                          &lt;p&gt;&lt;?php echo e($post-&gt;main_body); ?&gt;&lt;/p&gt;
                          &lt;div class="separator"&gt;&lt;/div&gt;
                          &lt;a href="&lt;?php echo e(route('posts.show', $post-&gt;id)); ?&gt;"&gt;&lt;button type="submit" class="button button-simple mt-30"&gt;Read More&lt;/button&gt;&lt;/a&gt;
                      &lt;/div&gt;
                      &lt;/a&gt;
                  &lt;/div&gt;
                &lt;?php endforeach; $__env-&gt;popLoop(); $loop = $__env-&gt;getLastLoop(); ?&gt;
  </code></pre>