How to use and save Emoji's on Laravel using Mysql

8k Views Asked by At

I have a web app I built using Laravel 5.2 , my question is how do I store then show emoji's. At the moment when I use an emoji from my iPhone , fire for instance, after saving the database returns ???? . Ive set the 'charset' = 'utf8mb4'; 'collation' = 'utf8mb4_unicode_ci'

but still get the same result. Do i need to install a package or something?

1

There are 1 best solutions below

6
Tomas Buteler On BEST ANSWER

Make sure you have the charset and collation correctly setup in the database config file as well, to ensure Laravel actually knows what charset to use when saving:

// config/database.php

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_general_ci',
    'prefix' => '',
    'strict' => false,
    'engine' => null,
],