im trying to view a graph but im having error Call to a member function orderBy() on integer what did i do wrong? i want it to view the 3 values which are "Match","Missing","No Aanswer".. i most probably think the error is from count().. what do you guys think? and how else can i chaneg it? i tried moving the count() to the end but then i have toArray() error..
my code for controller;
public function viewgraph($companyID)
{
$match = DiraChatLog::where('status','=','Match')->count()->orderBy("created_at")->groupBy("created_at")->get()->toArray();
$match = array_column($match, 'count');
$missing = DiraChatLog::where('status','=','Missing')->count()->orderBy("created_at")->groupBy("created_at")->get()->toArray();
$missing = array_column($missing, 'count');
$noAnswer = DiraChatLog::where('status','=','No Answer')->count()->orderBy("created_at")->groupBy("created_at")->get()->toArray();
$noAnswer = array_column($noAnswer, 'count');
return view('AltHr.Chatbot.viewgraph')->with('match',json_encode($match,JSON_NUMERIC_CHECK))->with('missing',json_encode($missing,JSON_NUMERIC_CHECK))->with('noAnswer',json_encode($noAnswer,JSON_NUMERIC_CHECK));
compact('companyID'));
}
and in my blade file:
<script src="https://raw.githubusercontent.com/nnnick/Chart.js/master/dist/Chart.bundle.js"></script>
<script>
var year = ['2013','2014','2015', '2016'];
var data_match = <?php echo $match; ?>;
var data_noAnswer = <?php echo $noAnswer; ?>;
var data_missing = <?php echo $missing; ?>;
var barChartData = {
labels: year,
datasets: [{
label: 'Match',
backgroundColor: "rgba(220,220,220,0.5)",
data: data_match
}, {
label: 'No Answer',
backgroundColor: "rgba(151,187,205,0.5)",
data: data_noAnswer
}, {
label: 'Missing',
backgroundColor: "rgba(173,187,205,0.5)",
data: missing
}]
};
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
elements: {
rectangle: {
borderWidth: 2,
borderColor: 'rgb(0, 255, 0)',
borderSkipped: 'bottom'
}
},
responsive: true,
title: {
display: true,
text: 'Unique Visitors'
}
}
});
};
</script>
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="panel-body">
<canvas id="canvas" height="280" width="600"></canvas>
</div>
</div>
</div>
</div>
</div>
->count()->orderBy.. What are you expecting to happen here?->count()??->toArray()?? do you need only count??