title: HTML Special Characters and Emojis Showing up Incorrectly on Laravel Webpage
body: <p>I am likely doing something silly and thought this would be pretty straightforward. I am pulling data from an external API and storing it right into the database via Eloquent model's I am creating/saving.</p>
  <p>The data saved into the database field looks like this:
  <code>I Can&amp;#039;t Believe It&amp;#039;s A</code> - The field is using <code>utf8mb4_unicode_ci</code> collation.</p>
  <p>My webpage has the following meta data:</p>
  <p><code>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;</code></p>
  <p>And I am displaying it via my Laravel blade template like so:</p>
  <p><code>&lt;td&gt;{{ $company-&gt;type-&gt;name }}&lt;/td&gt;</code></p>
  <p>I am a bit confused what I am doing wrong here? From the documentation and other stackoverflow questions I appear to be doing it correctly. My <code>config/database.php</code> has the following:</p>
  <pre><code>        'mysql' =&gt; [
              'driver' =&gt; 'mysql',
              'url' =&gt; env('DATABASE_URL'),
              'host' =&gt; env('DB_HOST', '127.0.0.1'),
              'port' =&gt; env('DB_PORT', '3306'),
              'database' =&gt; env('DB_DATABASE', 'forge'),
              'username' =&gt; env('DB_USERNAME', 'forge'),
              'password' =&gt; env('DB_PASSWORD', ''),
              'unix_socket' =&gt; env('DB_SOCKET', ''),
              'charset' =&gt; 'utf8mb4',
              'collation' =&gt; 'utf8mb4_unicode_ci',
              'prefix' =&gt; '',
              'prefix_indexes' =&gt; true,
              'strict' =&gt; true,
              'engine' =&gt; 'InnoDB',
              'options' =&gt; extension_loaded('pdo_mysql') ? array_filter([
                  PDO::MYSQL_ATTR_SSL_CA =&gt; env('MYSQL_ATTR_SSL_CA'),
              ]) : [],
          ],
  </code></pre>
  <p>I believe this is all correct. Is there something I am missing here? Switching to use the unescaped <code>{!! !!}</code> seems to result in the content still being displayed the same. I am using Laravel v7.13.0</p>
  <p>Also Google Chrome reports it is UTF-8 rendered:</p>
  <pre><code>&gt; document.characterSet
  &quot;UTF-8&quot;
  </code></pre>
  <p>Edit:</p>
  <p>Here is an example of getting the response and what the returned JSON name looks like:</p>
  <pre><code>&gt;&gt;&gt; $response = Http::withOptions(
              [
                  'verify' =&gt; false,
                  'base_uri' =&gt; config('custom.torn_api_base'),
                  'timeout' =&gt; 5.0
              ]
          )-&gt;get(
              &quot;company/79831&quot;,
              [
                  'selections' =&gt; 'profile',
                  'key' =&gt; config('custom.torn_api_key')
              ]
          );
  =&gt; Illuminate\Http\Client\Response {#3393
       +&quot;cookies&quot;: GuzzleHttp\Cookie\CookieJar {#3379},
       +&quot;transferStats&quot;: GuzzleHttp\TransferStats {#3418},
     }
  
  &gt;&gt;&gt; $response-&gt;json()['company']['name'];
  =&gt; &quot; Button Mashers™&quot;
  </code></pre>
  <p>^ You can see above their API is giving me the same string with the UTF-8 encoding that would be used on their website.</p>
  <p>Here is me creating and saving the model to the database:</p>
  <pre><code>            $company = Company::updateOrCreate(
                  [
                      'id' =&gt; $tornPlayerData['job']['company_id']
                  ],
                  [
                      'name' =&gt; $tornPlayerData['job']['company_name'],
                      'player_id' =&gt; $this-&gt;player-&gt;id,
                      'isOwner' =&gt; true
                  ]
              );
  </code></pre>
  <p>I also am logging the response and here is what one of the lines with an Emoji looks like:</p>
  <pre><code>Log::info(&quot;Updating company '{$company-&gt;name}'' now&quot;, ['company' =&gt; $company]);
  
  laravel.log│[2020-06-22 00:43:52] staging.INFO: Updating company '&amp;#128126; Button Mashers&amp;#8482;'' now {&quot;company&quot;:{&quot;App\\Company&quot;:{&quot;id&quot;:79831,&quot;name&quot;:&quot;&amp;#128126; Button Mashers&amp;#8482;&quot;,&quot;player_id&quot;:2141091,&quot;updated_at&quot;:&quot;2020-06-22T04:43:52.000000Z&quot;,&quot;created_at&quot;:&quot;2020-06-22T04:43:52.000000Z&quot;}}}
  </code></pre>
  <p>Edit 2:
  I just manually copied and pasted the Tinker output of <code> Button Mashers™</code> to <code>name</code> in the associated database row. Now the website displays that manually adjusted one properly. So it seems Laravel is doing something weird to the data from the API when it is storing it and I am unsure why that would be.</p>
  <p>Edit 3:</p>
  <p>Using the <code>HEX</code> query as the user asked in the answer.</p>
  <pre><code>SELECT id,name,HEX(name) FROM `companies` WHERE id=60335
  
  (60335, 'Pokey&amp;#039;s Play House!', '506F6B657926233033393B7320506C617920486F75736521');
  
  (60335, '&amp;#039;', '26233033393B');
  </code></pre>
  <p>The second result is with me modifying the <code>Pokey&amp;#039;s Play House!</code> to just <code>&amp;#039;</code> so you can see the result of just the apostrophe.</p>
  <p>Edit 4:</p>
  <p>The blade template:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;{{ str_replace('_', '-', app()-&gt;getLocale()) }}&quot;&gt;
      &lt;head&gt;
          &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
          &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  
          &lt;title&gt;Company Directory&lt;/title&gt;
  
          &lt;!-- Fonts --&gt;
  {{--        &lt;link href=&quot;https://fonts.googleapis.com/css?family=Nunito:200,600&quot; rel=&quot;stylesheet&quot;&gt;--}}
  
          &lt;!-- Styles --&gt;
            ** Snipped some minor CSS away from here **
          &lt;/style&gt;
          &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css&quot;&gt;
  
          &lt;!-- Scripts --&gt;
  
          &lt;script type=&quot;text/javascript&quot; charset=&quot;utf8&quot; src=&quot;https://code.jquery.com/jquery-3.5.1.slim.min.js&quot;&gt;&lt;/script&gt;
          &lt;script type=&quot;text/javascript&quot; charset=&quot;utf8&quot; src=&quot;https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js&quot;&gt;&lt;/script&gt;
          &lt;script type=&quot;text/javascript&quot; charset=&quot;utf8&quot;&gt;
              **removed some datatables code from here for this paste**
          &lt;/script&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;table id='directory-table' class='display'&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Player Name&lt;/th&gt;
                      &lt;th&gt;Company Name&lt;/th&gt;
                      &lt;th&gt;Type&lt;/th&gt;
                      &lt;th&gt;Rank&lt;/th&gt;
                      &lt;th&gt;Positions&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  @forelse ($companies as $company)
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;a href='https://www.example.
  net/profiles.php?XID={{ $company-&gt;player-&gt;id }}'&gt;
                                  {{ $company-&gt;player-&gt;name }}
                              &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;a href='https://www.example.net/joblist.php#/p=corpinfo&amp;userID={{ $company-&gt;id }}'&gt;
                                  {{ $company-&gt;name }}
                              &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;td&gt;{{ $company-&gt;type-&gt;name }}&lt;/td&gt; //THIS IS THE PROBLEM STRING HERE BEING OUTPUTTED
                          &lt;td&gt; {{ $company-&gt;rank }}&lt;/td&gt;
                          &lt;td&gt; {{ $company-&gt;hired_employees }}/{{ $company-&gt;max_employees }}&lt;/td&gt;
                      &lt;/tr&gt;
                  @empty
                      &lt;tr&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  @endforelse
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>