Laravel 5.1 utf-8 保存到数据库 [英] Laravel 5.1 utf-8 saving to database

查看:39
本文介绍了Laravel 5.1 utf-8 保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将记录保存到数据库.从输入中获取值并将其保存到数据库时没有问题,例如:

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',

推荐答案

  1. 将你的数据库文件配置为utf8_unicode_ci

检查文件 config/database.php :

'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',

  1. 确保你的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆