I have this dropdown with looped item in it. All I want is when I change the value of the selected item on dropdown it will send the value to the controller using route.
This is the code of looped item in my dropdown in my view named resolution_time_of_calls.blade.php
:
<div class="dropdown">
<form action="" method="POST">
<select name="year">
<option class="dropdown-item" selected name="years" disabled>--Select Year-- </option>
<?php
$start = "2017";
$end = (int)date("Y");
for($i=$start; $i<=$end; $i++){
echo '<option class="dropdown-item" value='.$i.'>'.$i.'</option>';
}
?>
</select>
</form>
</div>
This is a screenshot of my dropdown:
All I want is when I changed the Year on my dropdown
, the year below the graph will change its year.
I don't have a route for that yet because I don't know what code to write.
This is my controller where the dropdown value should be passed. The value that will be sent by the route should be passed into this function and I don't know how because I'am a newbie in Laravel. Thanks in advance for the help!
public function resolution_time_of_calls(){
//declarations
$arr_val = array();
$arr_val1 = array();
$arr_val2 = array();
$arr_monthname = array();
$arr_monthInt = array();
//SELECTING MONTHS
$quer = DB::select("SELECT MONTH(DATE_ADD(T.Created, INTERVAL 8 HOUR)) AS MonthInt
,monthname(DATE_ADD(T.Created, INTERVAL 8 HOUR)) AS Month
,year(DATE_ADD(T.Created, INTERVAL 8 HOUR)) AS Year
FROM rtdb.Tickets T
LEFT JOIN rtdb.ObjectCustomFieldValues O ON O.ObjectId=T.EffectiveId
AND O.CustomField=15 AND O.ObjectType='RT::Ticket' AND O.Disabled=0
WHERE T.Status!='Deleted' AND T.IsMerged IS NULL AND T.Type='ticket'
AND year(DATE_ADD(T.Created, INTERVAL 8 HOUR))=2018
GROUP BY Month,MonthInt,Year Order by MonthInt asc
");
$chart = new SampleChart;
$chart->title('Resolution Time of Calls');
foreach($quer as $query){
array_push($arr_monthname, $query->Month.", ".$query->Year);
array_push($arr_monthInt, $query->MonthInt);
}
$chart->labels($arr_monthname);
///////////////////// TOTAL, AVERAGE,MAXIMUM Query ////////////////////
foreach($arr_monthInt as $month){
$sql = DB::select("SELECT MONTH(DATE_ADD(T.Created, INTERVAL 8 HOUR)) AS MonthInt
,AVG(TIMESTAMPDIFF(HOUR,T.Created,O.Created)) AS AVG
,MAX(TIMESTAMPDIFF(HOUR,T.Created,O.Created)) AS MAX
FROM rtdb.Tickets T
LEFT JOIN rtdb.ObjectCustomFieldValues O ON O.ObjectId=T.EffectiveId
AND O.CustomField=15 AND O.ObjectType='RT::Ticket' AND O.Disabled=0
WHERE T.Status!='Deleted' AND T.IsMerged IS NULL AND T.Type='ticket'
AND year(DATE_ADD(T.Created, INTERVAL 8 HOUR))=2018
GROUP BY MonthInt Order by MonthInt asc");
}
foreach($sql as $value){
array_push($arr_val1, $value->AVG );
array_push($arr_val2, $value->MAX );
}
$chart->dataset('Average Hours', 'bar', $arr_val1)->backgroundcolor('green');
$chart->dataset('Maximum Hours', 'bar', $arr_val2)->backgroundcolor('blue');
$chart->height(600);
return view('resolution_time_of_calls',['chart'=>$chart]);
}
您可以使用Javascript onchange事件获取选定年份的值,并将其作为路由参数传递给控制器。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.