Ad

How Json Encode Arabic In Laravel 5.2 Json Response?

My application supporting multiple language.

My Controller,

 public function index(Request $request) {
    return DB::table('offer_types')
                    ->join('offer_type_details', 'offer_type_details.offer_types_id', '=', 'offer_types.id')
                    ->where('offer_type_details.languages_id', $request->language_id ? $request->language_id : 1)
                    ->get();
}

In case of Arabic, it returns following json,

    [{
    "id": 1,
    "description": "desc",
    "offer_types_id": 1,
    "languages_id": 2,
    "title": "\u062d\u0632\u0645"
}, {
    "id": 2,
    "description": "desc",
    "offer_types_id": 2,
    "languages_id": 2,
    "title": "\u0641\u0646\u0627\u062f\u0642"
}]

How can I encode this arabic value in Laravel 5.2?

Ad

Answer

Try to do this:

$data = DB::table('offer_types')
                    ->join('offer_type_details', 'offer_type_details.offer_types_id', '=', 'offer_types.id')
                    ->where('offer_type_details.languages_id', $request->language_id ? $request->language_id : 1)
                    ->get();

return Response::json($data, 200, [], JSON_UNESCAPED_UNICODE);

Or

return response()->json($data, 200, [], JSON_UNESCAPED_UNICODE);
Ad
source: stackoverflow.com
Ad