Laravel 5.1 utf-8 保存到数据库 [英] Laravel 5.1 utf-8 saving to database
问题描述
我正在尝试将记录保存到数据库.从输入中获取值并将其保存到数据库时没有问题,例如:
I'm trying to save a record to database. When get value from input and save it to database there is no problem, like :
$request->input('name') 是一个值为 'سلام' 的输入
$request->input('name') is an input with value of 'سلام'
$provider->name = $request->input('name');
$provider->copyright_email = 'test@yahoo.com';
$provider->save();
但是当我尝试从我的控制器中给出值时出现问题.名称将保存?"进入数据库:
But when i try give value from my controller problem appears. Name will save '?' into database :
$provider->name = 'سلام';
$provider->copyright_email = 'test@yahoo.com';
$provider->save();
我已经将此代码添加到 config/database.php :
I've already added this code to config/database.php :
'charset' => 'utf8',
'collation' => 'utf8_persian_ci',
推荐答案
- 将你的数据库文件配置为
utf8_unicode_ci
检查文件 config/database.php
:
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
确保你的Mysql数据库设置为
utf8
并且MySQL的utf8mb4
更好
确保您的文件字符设置为UTF-8 without BOM
Make sure your file character set to UTF-8 without BOM
我个人认为您的 IDE 有问题,请尝试使用 Atom.
I personally think you problem in you IDE, try to use Atom.
这篇关于Laravel 5.1 utf-8 保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!