title: Laravel collection with if condition
body: <p>I'm using laravel collection <code>random</code> to get some of other posts in single post blade but the problem is when i don't have more that 6 posts i'll get error of 
  <code>You requested 6 items, but there are only 1 items in the collection.</code></p>
  
  <p>So now I need to make an if statement to say get random posts from 0 to 6 which means if for example i have only one post and i'm in view of that post so ignore of getting other posts (cause there is no other post!) and if i have 2 posts in total get only other one and so on... till maximum 6 posts in random order.</p>
  
  <p>here is my function:</p>
  
  <pre><code>public function show($slug) {
        $post = Post::where('slug', $slug)-&gt;firstOrFail();
        $postfeatures = Post::all()-&gt;random(6);
        $subcategories = Subcategory::with('posts')-&gt;get();
        $categories = Category::all();
        $advertises = Advertise::inRandomOrder()-&gt;where('status', '1')-&gt;first();
        return view ('frontend.single', compact('post', 'categories', 'subcategories', 'postfeatures', 'advertises'));
      }
  </code></pre>
  
  <p>Here is my view:</p>
  
  <pre><code>&lt;ul class="gallery"&gt;
     @foreach($postfeatures as $postss)
       &lt;li&gt;&lt;a data-toggle="tooltip" data-placement="top" title="{{ $postss-&gt;title }}" href="{{ route('frontshow', $postss-&gt;slug ) }}"&gt;&lt;img src="{{ url('images/') }}/{{ $postss-&gt;image }}" class="img-responsive" alt="{{ $postss-&gt;title }}"&gt;&lt;/a&gt;&lt;/li&gt;
     @endforeach
  &lt;/ul&gt;
  </code></pre>
  
  <p>Thanks.</p>