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') 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();

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

'charset' => 'utf8',
'collation' => 'utf8_persian_ci',
Ihab Shoully
  • 2,311
  • 1
  • 20
  • 22
A. Najafi
  • 103
  • 1
  • 1
  • 4
  • Is your IDE/Text editor configured to use UTF-8? – Javi Stolz Sep 30 '15 at 13:40
  • @JaviStolz Thanks for replay. Yes. I'm using phpstorm and as you can see link below encoding configured to utf-8 [picture](http://imgur.com/soX7f1z) – A. Najafi Sep 30 '15 at 14:48
  • read this https://www.jetbrains.com/phpstorm/help/file-encodings.html – patricio Sep 30 '15 at 16:12
  • Where did you save this file? in your controller ? the file that contain "$provider->name = 'سلام';" , if yes, does your controller file is uni-coded? can you try to create the new file with Atom editor and try ? – Ihab Shoully Sep 30 '15 at 17:31
  • @Shoully Thanks for replay. Yeah ! Just opened file with notepad++ and set it to encode utf-8 and after saving there was no problem. Don't know if i must do this manually for every single file which i use in my project, actually the picture and code i attached just was a test. – A. Najafi Oct 01 '15 at 08:32
  • No, you don't have to do it manually, It's just your file was created with that character set, you can config PHPstorm to create any new file with utf-8 like @patricio said in the link. – Ihab Shoully Oct 02 '15 at 14:58

5 Answers5

12
  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.

Ihab Shoully
  • 2,311
  • 1
  • 20
  • 22
  • "**1. ...**": Collation is only sorting algorithm, hence not relevant. "**2. ...**": is already, as OP mentioned Databese is operating sometimes. "**3. ...**": thanks, that was OP's real issue. – Top-Master Jun 05 '22 at 03:13
1

config your database file to utf8mb4_unicode_ci

Check the file config/database.php :

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

Habib
  • 34
  • 8
1

im problem use

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

not work

but use into migration

$table->charset = 'utf8';
$table->collation = 'utf8_persian_ci';
Netwons
  • 1,170
  • 11
  • 14
0

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. :)

Ahmad.Net
  • 581
  • 5
  • 8
0

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