title: How to pass data in Laravel with Chart.js
body: <p>I want to display total of men and woman from learnings table in chart using Chartjs in Laravel.</p>
  
  <p>My controller</p>
  
  <pre class="lang-php prettyprint-override"><code>public function index()
  {
      $men_learning = DB::table('learnings')-&gt;where('active', 1)-&gt;whereYear('created_at', $year)-&gt;sum('men');
      $women_learning = DB::table('learnings')-&gt;where('active', 1)-&gt;whereYear('created_at', $year)-&gt;sum('women');
      $learning = $men_learning + $women_learning  ;
      return view('home', compact('learning'));
  }
  </code></pre>
  
  <p>My script in blade view. </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script&gt;
      var ctx = document.getElementById('myChart').getContext('2d');
      var myChart = new Chart(ctx, {
          type: 'bar',
          data: {
              labels: ['total'],
              datasets: [{
                  label: '# of Votes',
                  data: [12],
                  backgroundColor: [
                      'rgba(255, 99, 132, 0.2)',
  
                  ],
                  borderColor: [
                      'rgba(255, 99, 132, 1)',
                  ],
                  borderWidth: 1
              }]
          },
          options: {
              scales: {
                  yAxes: [{
                      ticks: {
                          beginAtZero: true
                      }
                  }]
              }
          }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>How can I propagate loaded statistic from my script to the chart?</p>