The variable current_restroom_id in the script cannot be passed to the Controller in Laravel.
console.log('{{HomeController::getTrendingIssue('1',current_restroom_id)}}');
// but this is not passing script variable value.
Please help to resolve this.
Here is the related code in blade file:
<div class="p-t-20">
<div class="row">
<div class="col s12">
<style>
#chartdiv3 {
width: 100%;
height: 500px;
}
</style>
<!-- Chart code -->
<script>
var current_restroom_id = '14';
am4core.ready(function() {
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.create("chartdiv3", am4charts.PieChart3D);
chart.hiddenState.properties.opacity = 0; // this creates initial fade-in
console.log('{{HomeController::getTrendingIssue('1', '14')}}'); // this works fine console.log('{{HomeController::getTrendingIssue('1',current_restroom_id)}}'); // but this is not passing script variable value.
console.log(current_restroom_id); // This prints 14 in console
chart.data = [
{
"issues" :'{{HomeController::getIssueName('1')}}',
"dislikes" :'{{HomeController::getTrendingIssue('1', current_restroom_id)}}'
},
{
"issues" :'{{HomeController::getIssueName('2')}}',
"dislikes" :'{{HomeController::getTrendingIssue('2', current_restroom_id)}}'
},
{
"issues" :'{{HomeController::getIssueName('3')}}',
"dislikes" :'{{HomeController::getTrendingIssue('3', current_restroom_id)}}'
},
{
"issues" :'{{HomeController::getIssueName('4')}}',
"dislikes" :'{{HomeController::getTrendingIssue('4', current_restroom_id)}}'
},
{
"issues" :'{{HomeController::getIssueName('5')}}',
"dislikes" :'{{HomeController::getTrendingIssue('5', current_restroom_id)}}'
},
{
"issues" :'{{HomeController::getIssueName('6')}}',
"dislikes" :'{{HomeController::getTrendingIssue('6', current_restroom_id)}}'
}
];
</script>
<div id="chartdiv3"></div>
</div>
</div>
</div>
Here is the HomeController function:
public static function getTrendingIssue($issue_id, $restroom_id)
{
$issue_count = DB::table('ticket_manages')
->where(['ticket_manages.issue_id' => $issue_id, 'restroom_id' => $restroom_id])
->count();
return $issue_count;
}