Laravel 5 eloquent not storing special characters in database Laravel 5 eloquent not storing special characters in database database database

Laravel 5 eloquent not storing special characters in database


What you're seeing there is the text being replaced with HTML entities this usually is the result of text coming directly from an HTML source (either a form with text that was previously converted to htmlentities or an other source).

The ideal solution here is to ensure that the text is not received as HTML entity encoded, however if this is not an option (which it very often is not), you can use:

 $decoded = html_entity_decode($text); 

to decode the entities into their actual characters before you insert them.

A bit of trivia:

You don't actually need to encode all characters to their corresponding entities to display on HTML as long as you're properly sending Unicode text. This is why PHP has 2 different functions htmlspecialchars and htmlentities where the first function only encodes what is necessary to encode in order to not break HTML (those 5 characters listed in the manual, <, >, &, " and ') while the second one encodes everything based on the linked table.


In your Database.php insert :

'charset'   => 'utf8','collation' => 'utf8_unicode_ci',

This should allow you from saving the string in the format you want.

And please make sure that your MySQL is set to utf8