Luna
Luna

Reputation: 557

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

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?

Upvotes: 6

Views: 8376

Answers (1)

Tomas Buteler
Tomas Buteler

Reputation: 4117

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

Upvotes: 13

Related Questions