title: Laravel - Foreach loop - Show a specific message for types of result
body: <p>So I have a messages table with all messages. I want pinned messages to be at top and normal ones to follow after. I have been able to do this normally with the <code>orderBy()</code> method in my query.</p>
  
  <p>However, I want to display some specific messages for all my pinned messages. I would like to have a header at the top of the pinned messages and a header at the top of the normal messages to let users know that pinned and normal messages are there.</p>
  
  <p>Example:</p>
  
  <p>My query:</p>
  
  <pre><code>$rows = Messages::where('active', true)-&gt;orderBy('pinned', 'desc')-&gt;get();
  </code></pre>
  
  <p>My view</p>
  
  <pre><code>@foreach ($rows as $row)
      {{ $row-&gt;message }}
  @endforeach
  </code></pre>
  
  <p>What I see</p>
  
  <pre><code>Message text 3
  Message text 1
  Message text 2
  </code></pre>
  
  <p>I have a few messages with "pinned" in the column in database. So I want the pinned ones to show at the top WITH DESCRIPTIONS. Something like this:</p>
  
  <pre><code>Pinned
  ----------
  Message text 3
  ----------
  Normal
  ----------
  Message text 1
  Message text 2
  </code></pre>
  
  <p>I have tried <code>orderBy()</code> and it's working pretty good, in terms of ordering it from pinned to normal, but I can't get it to show the "Pinned" and "Normal" message. How can I do this?</p>