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
And this is my database in phpmyadmin
Thanks
To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.
MySQL supports multiple Unicode character sets: utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four bytes per character. utf8mb3 : A UTF-8 encoding of the Unicode character set using one to three bytes per character. This character set is deprecated in MySQL 8.0, and you should use utfmb4 instead.
Definition and Usage. The utf8_encode() function encodes an ISO-8859-1 string to UTF-8. Unicode is a universal standard, and has been developed to describe all possible characters of all languages plus a lot of symbols with one unique number for each character/symbol.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With