app/Http/Controllers/Api/JsonResponseTrait.php
<?php
namespace App\Http\Controllers\Api;
trait JsonResponseTrait
{
/**
* JSON_UNESCAPED_UNICODE オプションを使用して JSON レスポンスを返す
*
* @param mixed $data
* @param int $code
* @return \Illuminate\Http\JsonResponse
*/
public function unescapedJsonResponse($data, $code = 200)
{
return response()->json(
$data,
$code,
['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8'],
JSON_UNESCAPED_UNICODE
);
}
}
// trait
use JsonResponseTrait;
public function show(string $id)
{
$event = Event::inActive()->findOrFail($id);
// return response()->json($event); この行を以下に変更 ↓
return $this->unescapedJsonResponse($event);
}