8

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

Miguél

When i start using eloquent the following happens.

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

This produces the following result

migu��l

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

Thanks

Community
  • 1
  • 1
Miguel Stevens
  • 8,631
  • 18
  • 66
  • 125

1 Answers1

16

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.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • 1
    That's it! How clever of you. I didn't even post the strtolower() code. is mb_strtolower() good practice? or is there another way i should do this! – Miguel Stevens Oct 13 '14 at 16:50
  • 7
    @MiguelStevens For any operations on UTF-8 strings you should use `mb_` functions to handle national characters without a problem - http://php.net/manual/en/ref.mbstring.php – Marcin Nabiałek Oct 13 '14 at 16:51