Support the ongoing development of Laravel.io →
Views Laravel Blade

I have this dropdown, All I want is to pass the selected dropdown value on controller method directly.

This is my code for my dropdown.

 <form method="POST" >          
<select name="year" id="year">
               <option disabled selected name="years" value="100">--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>

This is my code for my method in my controller.

 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('#00833E');   
                    $chart->dataset('Maximum Hours', 'bar', $arr_val2)->backgroundcolor('#AF1D2D');   
                    $chart->height(600);

             return view('resolution_time_of_calls',['chart'=>$chart]);
    }
Last updated 3 years ago.
0

Do you mean on form submit or on the select of the drop down ?

If you want to run a method on drop down select you may have to use JavaScript to make a call to an endpoint and run your method in that endpoint and return the data you need to JavaScript . If it’s the value on form submit make a post route pointing at your controller method

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Charlie charlie023 Joined 19 Feb 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.