title: Laravel - how to update my value in variable and put into session laravel?
body: <p>I have variable getscore in my controller function ?</p>
  
  <pre><code> public   function questionquiz5(Request $request){
  
  
             static $getscore=0;
  
       $getidvalue = Input::get('getid');
       $getanswervalue = Input::get('getanswer');
  
       $dbscore = \DB::table('5question')-&gt;select('question_id','correct_answer','question_marks')-&gt;
       where('question_id','=',$getidvalue)-&gt;get();
  
     foreach ($dbscore as $value) {
  
         if ( $getanswervalue==($value-&gt;correct_answer) ){
  
                         $this-&gt;getscore  =  $this-&gt;getscore + $value-&gt;question_marks;           
  
            }elseif($getanswervalue == null){
  
                         $emptyvalue = -1;
                         $this-&gt;getscore += $emptyvalue;
  
            }else{
  
                         $novalue=0;
                         $this-&gt;getscore += $novalue;               
            }
  
      }
            echo "$this-&gt;getscore";
  
  
         Session::push('getscoresession',$this-&gt;getscore);
  
  
      $getsession = [  'qid' =&gt; $getidvalue,  'answer' =&gt; $getanswervalue];
  
         Session::push('answer', $getsession);
  
      return response()-&gt;json(['qid'=&gt;$getidvalue,'answer'=&gt;$getanswervalue]);       
  </code></pre>
  
  <p>}     </p>
  
  <p>i want to increase my value of getscore my applying foreach loop but not working ....as it always resets to zero i think?
  how to make it happen so when i run loop so my getscore value added and stored in session ?</p>