Laravel UTF-8 To Database

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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

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

And this is my database in phpmyadmin

Thanks

回答1:

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.



转载请标明出处:Laravel UTF-8 To Database
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!