Laravel 回傳 json的亂碼解決方式

在Laravel中我們要產出json格式的話,一般只要
[php]
Route::get(‘json’, function () {
$users = DB::table(‘users’)->get();
return Response::json($users);
}
[/php]
但是遇到中文時,會出現有亂碼的問題,解決很簡單
[php]
Route::get(‘json’, function () {
$headers = array(‘Content-Type’ => ‘application/json; charset=utf-8’);
$users = DB::table(‘users’)->get();
return Response::json($users, 200, $headers, JSON_UNESCAPED_UNICODE);
});
[/php]