I want to store special character in database vice versa like emotive but when I try to save in database I get question marks.
To get the latest version of Laravel Emoji, simply add the following line to the require block of your composer. json file. You'll then need to run composer install or composer update to download it and have the autoloader updated. Once Laravel Emoji is installed, you need to register the service provider.
We will have to set our connection charset to utf8. After declaring connection variable set charset: mysqli_set_charset($con,"utf8"); After that your emoji or any other unicode text will be encrypted and saved in mysql database.
You need to use utf8mb4 encoding in your mysql database in order to be able to store emojis.
In your database.php
file, make sure to set the charset
and collation
to utf8mb4
:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
And your emoji column should be a String:
$table->string('emoji');
1) Ensure you're using MYSQL 5.5.3 or later then will you be able to change the collation to utf8mb4_something,
2) Ensure table columns that are going to receive emoji have their collation set to utf8mb4_something
if still you have issue, then Edit your database.php config file and update following,
'charset' = 'utf8mb4';
'collation' = 'utf8mb4_unicode_ci'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With