How to store emoji string in Database using Laravel with Orm Query

半世苍凉 提交于 2020-02-03 08:22:47

问题


I want to store special char in database vice versa like emotive but when i try to save in database i get question marks.

Please help


回答1:


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




回答2:


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'



回答3:


In addition to the answers above, make sure to clear cache and migrate refresh to update the mysql tables. hope this helps someone




回答4:


If you are using websocket for chat and sending Emoticons, then you have to restart the websocket.

You can find and kill all the websocket processes like sudo kill (Your PID) without the round brackets.

And for the ??? marks, its okey because some browsers, or MYSQL editors not supporting Emoticons, so they show you questions (?) marks.

Regards.



来源:https://stackoverflow.com/questions/38636783/how-to-store-emoji-string-in-database-using-laravel-with-orm-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!