Home » Php » php – Laravel UTF-8 To Database

php – Laravel UTF-8 To Database

Posted by: admin July 12, 2020 Leave a comment


I’m using Eloquent to save() a new person into my database. The persons name contains a special character é and it’s not submitting. Here are my steps and the results.

echo Input::get('firstname'); // Miguél

Which gives me this


When i start using eloquent the following happens.

$person = new Person();
echo $person->firstname = Input::get('firstname'); 

This produces the following result


Any idea what might be going wrong?
These are my config settings in laravel

enter image description here

And this is my database in phpmyadmin

enter image description here


How to&Answers:

I don’t think it has anything common with database.

When you use:

$person = new Person();
echo $person->firstname = Input::get('firstname'); 

you don’t use database in here. You just assign properties to Person class (that probably uses Eloquent) but you don’t put anything into database and get anything from database so it’s not possible that the encoding problem has anything in common with database itself

Potential problem in my opinion – you have defined mutator in Person class for firstname attribute because you have it in lowercase (when you get it from Input it’s with capital letter) so you probably use some function like strtolower and you should use mb_strtolower to convert UTF-8 strings without a problem.