在laravel上运行set names query和json unicode

时间:2021-01-06 20:24:00

I'm new on Laravel
and I search for a way to run queries
I'm not talking about select etc...
I want to run this query:

我是Laravel的新手,我搜索运行查询的方法我不是在谈论选择等...我想运行这个查询:

 SET NAMES 'utf8'

This is question number one, Now question number two:
I have data writen in hebrew in my db and when I do on Laravel this code:

这是第一个问题,现在问题二:我在我的数据库中用希伯来语写了数据,当我在Laravel上写这个代码:

    $todolist = DB::select('select * from todo');
    return $todolist;

I get this result:

我得到这个结果:

[{"id":1,"name":"\u05d1\u05dc\u05d4 \u05d1\u05dc\u05d4 \u05d1\u05dc\u05d4","done":0},{"id":2,"name":"\u05d1\u05dc\u05d4 \u05d1\u05dc\u05d4 \u05d1\u05dc\u05d4","done":1}]

What is this? unicode? how can I turn it to hebrew again? My mission is to send it back to client side and then show it on the web page
How can I translate this from unicode to hebrew with Java Script ?

这是什么? Unicode的?我怎么能再把它变成希伯来语?我的任务是将其发送回客户端然后在网页上显示我如何使用Java Script将其从unicode转换为希伯来语?

1 个解决方案

#1


0  

You can use the statement method of the DB class, like so:

您可以使用DB类的语句方法,如下所示:

DB::statement("SET NAMES 'utf8'");

I'm not entirely aware of the situation but I would recommend this be within a migration.

我并不完全了解这种情况,但我建议将其纳入迁移范围。

Regarding the unicode characters, those should render in views correctly and should be usable within Javascript (see http://codepen.io/anon/pen/LZpOqY)

关于unicode字符,那些应该在视图中正确呈现并且应该可以在Javascript中使用(参见http://codepen.io/anon/pen/LZpOqY)

#1


0  

You can use the statement method of the DB class, like so:

您可以使用DB类的语句方法,如下所示:

DB::statement("SET NAMES 'utf8'");

I'm not entirely aware of the situation but I would recommend this be within a migration.

我并不完全了解这种情况,但我建议将其纳入迁移范围。

Regarding the unicode characters, those should render in views correctly and should be usable within Javascript (see http://codepen.io/anon/pen/LZpOqY)

关于unicode字符,那些应该在视图中正确呈现并且应该可以在Javascript中使用(参见http://codepen.io/anon/pen/LZpOqY)