A. Najafi
A. Najafi

Reputation: 103

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

Upvotes: 8

Views: 37030

Answers (5)

Netwons
Netwons

Reputation: 1648

im problem use

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

not work

but use into migration

$table->charset = 'utf8';
$table->collation = 'utf8_persian_ci';

Upvotes: 1

Alireza Salehi
Alireza Salehi

Reputation: 43

also you can use below code for setting utf8 ->charset('utf8')

Upvotes: 0

Habib
Habib

Reputation: 34

config your database file to utf8mb4_unicode_ci

Check the file config/database.php :

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

Upvotes: 1

Ahmad.Net
Ahmad.Net

Reputation: 581

I faced the same issue, the accepted answer dose not help me. Here how i solved the issue in this way:

Go to your table in your DB, check the 'Collation', change it to :

utf8mb4_unicode_ci  

Apply this to each field in the table.

This may help somebody. :)

Upvotes: 0

Ihab Shoully
Ihab Shoully

Reputation: 2321

  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.

Upvotes: 12

Related Questions