title: How properly use utf8_decode at Laravel controller json response?
body: <p>I'm in a struggle working with Laravel JSON response.</p>
  
  <p>What I'm trying to do, is create a CURL request to Laravel controller.</p>
  
  <p>So this is the CURL code:</p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'http://dev.laravel/');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($ch);
  curl_close($ch);
  echo $output;
  </code></pre>
  
  <p>... and this is the controller code:</p>
  
  <pre><code>$data = array(
      'code' =&gt; ($this-&gt;code ? $this-&gt;code : 0),
      'message' =&gt; 'àèìòù',
      'data' =&gt; ''
  );
  return response()-&gt;json($data);
  </code></pre>
  
  <p>The problem is the message accentuation . But if I only return an string and use <code>utf8_decode($output)</code> the accentuation work as well, here's an example:</p>
  
  <pre><code>// curl
  echo utf8_decode($output);
  
  // laravel controller
  return 'àèìòù';
  </code></pre>
  
  <p>[UPDATE]</p>
  
  <p>Another example that doesn't work:</p>
  
  <pre><code>$response = array(
      'code' =&gt; 200,
      'message' =&gt; 'àèìòù',
      'data' =&gt; array()
  );
  return response()-&gt;json($response, 200, [], JSON_UNESCAPED_UNICODE);
  
  {"code":200,"message":"Ã Ã¨Ã¬Ã²Ã¹","data":[]} // result
  </code></pre>