title: Joining two tables within Laravel Controller
body: <p>I have two tables that I am joining within my controller - <code>thought_journal_entries</code> and <code>emotions</code>. They have a many-to-many relationship which has been added to the models. </p>
  
  <p>I believe my code will work but I am getting the error: </p>
  
  <blockquote>
    <p>Malformed UTF-8 characters, possibly incorrectly encoded.</p>
  </blockquote>
  
  <p>I think my code is almost there I'm just not sure if I'm looping correctly to get the <code>emotion-&gt;image</code> field </p>
  
  <pre><code>$user_id = auth()-&gt;user()-&gt;id;
  $thought_journal_entries = ThoughtJournalEntry::with('emotions')-&gt;where('user_id', $user_id)-&gt;orderBy('created_at', 'desc')-&gt;paginate(15);
  
  foreach($thought_journal_entries as $thought_journal_entry) {
      foreach($thought_journal_entry-&gt;$emotions as $emotion) {
          $emotion-&gt;image = 'data:image/jpeg;base64,' . base64_encode( $emotion-&gt;image);
      }
  }
  return $thought_journal_entries;
  </code></pre>