Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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') is an input with value of 'سلام'

$provider->name = $request->input('name');
$provider->copyright_email = '[email protected]';
$provider->save();

But when i try give value from my controller problem appears. Name will save '?' into database :

$provider->name = 'سلام';
$provider->copyright_email = '[email protected]';
$provider->save();

I've already added this code to config/database.php :

'charset' => 'utf8',
'collation' => 'utf8_persian_ci',
like image 881
A. Najafi Avatar asked Sep 30 '15 13:09

A. Najafi


2 Answers

  1. config you database file to utf8_unicode_ci

Check the file config/database.php :

'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
  1. Make sure your Mysql databases is set to utf8 and MySQL’s utf8mb4 is better

  2. Make sure your file character set to UTF-8 without BOM

I personally think you problem in you IDE, try to use Atom.

like image 164
Ihab Shoully Avatar answered Nov 19 '22 18:11

Ihab Shoully


config your database file to utf8mb4_unicode_ci

Check the file config/database.php :

'charset' => 'utf8', 'collation' => 'utf8mb4_unicode_ci',

like image 1
Habib Avatar answered Nov 19 '22 18:11

Habib