title: Posts not displaying properly after if else loop put in
body: <p>2 problems:</p>
  
  <p>1) the Recent Posts function in my view file (for the single post page) no longer shows posts.<br>
  2) On the articles page which shows all of the posts, the posts with no slug do not work. when I click on the post, it redirects to /articles. Only posts with a slug work.</p>
  
  <p>I have 2 kinds of URLs for my posts: slug and url.  The difference?  URL is longer.  Slug is shorter and used for SEO purposes.  Why not use just slug?  Because for some posts, I don't want to waste time creating a slug.  The data in the slug column for those posts is blank/empty.  The generated url is fine.  For other posts, I want a slug made.</p>
  
  <p>Here is my controller code for posts.</p>
  
  <p>Old version:</p>
  
  <pre><code>public function viewpost($url,$slug){
  if ( empty($slug) ) {
  $url ='articles/'.$url;
  }  else {
  $url = 'articles/'.$slug;
  
  }
  
  $posts = posts::where('post_status', '')-&gt;get();
  if ( empty($slug) ) {
  $post = $posts-&gt;where('url', $url)-&gt;first();
  }  else {
  $post = $posts-&gt;where('slug', $slug)-&gt;first();
  }
  
  if ( empty($post) )
  return redirect()-&gt;back();
  
  
  return view('viewpost')-&gt;with('post', $post)-&gt;with('posts', $posts);
  }
  </code></pre>
  
  <p>New version (modified):</p>
  
  <pre><code>public function viewpost($url){
  
  
    $posts = posts::where('post_status', '');
    $post = $posts-&gt;where('url', $url)-&gt;orWhere('slug' , $url)-&gt;first();
  
  
    if ( empty($post) )
  return redirect()-&gt;back();
  
  
  return view('viewpost')-&gt;with('post', $post)-&gt;with('posts', $posts);
  }
  </code></pre>
  
  <p>The new modified controller file broke the posts without a slug.</p>
  
  <p>Here is the view file for the Recent Posts which broke:</p>
  
  <pre><code>&lt;h3&gt;Recent Posts&lt;/h3&gt;
   @foreach($posts as $post)
   &lt;p&gt;&lt;a href="{{ URL::to($post-&gt;url) }}"&gt;&lt;img style="width:100px;" src="{{asset('thumbnails/'.$post-&gt;thumbnail)}}" class="responsive"&gt;&lt;/a&gt;&lt;br&gt;
       &lt;a href="{{ URL::to($post-&gt;url) }}"&gt;{{substr(($post-&gt;title),0,88)}}.. 
   &lt;/a&gt;&lt;/p&gt;               
    @endforeach
  </code></pre>
  
  <p>My Routes code:</p>
  
  <pre><code>Route::get('articles/{url}', 'postsController@viewpost');
  </code></pre>
  
  <p>My view file code for the posts page which displays all the posts:</p>
  
  <pre><code>                    @foreach($post as $post)
  
                      &lt;div class="col-md-4"&gt;
  
                          &lt;div class="content"&gt;
                          @if(!empty($post-&gt;slug))
                              dd(11);
                          &lt;a href="{{'articles/'.$post-&gt;slug}}" class="latest-heading"&gt;{{substr(($post-&gt;title),0,88)}}..&lt;/a&gt;
  
                          @else
                          dd(22);
                          &lt;a href="{{($post-&gt;url)}}" class="latest-heading"&gt;{{substr(($post-&gt;title),0,88)}}..&lt;/a&gt;
                          @endif
                              &lt;img style="padding: 5px; width:100%; height:218px;" src="{{asset('thumbnails/'.$post-&gt;thumbnail)}}" class="img-responsive"&gt;
  
                          &lt;/div&gt;
  
                      &lt;/div&gt;
  
                     @endforeach
  </code></pre>