title: Ajax call at Laravel route that returns an json encoded array containing dates for ChartJS labels
body: <p>I have a Laravel 5.7 project, with ajax and ChartJS.</p>
  
  <p>At page load, I am making an ajax call to "<strong>action_route</strong>", which returns the labels for my ChartJS. The php function is json encoding an array of labels, and the ajax decodes them.</p>
  
  <pre><code>function get_data($year) {
      $test = \DB::select( \DB::raw("
          SELECT 
              DATE_FORMAT(date_for,'%c/%y') AS 'month',
              col1,
              col2,
              col3
          FROM test
          WHERE
              AND YEAR(date_for) = '" . $year . "'
          GROUP BY month
          ORDER BY month ASC
      ") );
  
      return $test;
  }
  
  public function action_route() {
     $data = self::get_data(2018);
     foreach($data as $x) {
        $labels[] = $x-&gt;month;
     }
  }
  
  return view('/test/get_data', [
       'labels' =&gt; json_encode($labels)
  ]);
  </code></pre>
  
  <blockquote>
    <p>DATE_FORMAT(date_for,'%c/%y') AS 'month' - Because I need dates if this format: '01/18', '02/18' etc.</p>
  </blockquote>
  
  <p>In template:</p>
  
  <pre><code>var labels = JSON.parse('{{ $labels }}');
  </code></pre>
  
  <p><strong>The Problem</strong>
  This is what get's put into html.</p>
  
  <p><a href="https://i.stack.imgur.com/wByK0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wByK0.png" alt="enter image description here"></a></p>