title: Laravel : Undefined variable in blade?
body: <p>In am getting Undefined variable: score (View: C:\Users\Sarthak\blog\resources\views\submitquestion.blade.php) in blade view when executing :</p>
  
  <p>Controller part</p>
  
  <pre><code>public function question(Request $request)
  {
      static $startscore = 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)) {
              $getscore = $startscore + $value-&gt;question_marks;
          }
          elseif ($getanswervalue == null) {
              $emptyvalue = - 1;
              $getscore = $startscore + $emptyvalue;
          }
          else {
              $novalue = 0;
              $getscore = $startscore + $novalue;
          }
      }
  
      echo "$getscore";
      Session::push('getscoresession', $getscore);
      $getsession = ['qid' =&gt; $getidvalue, 'answer' =&gt; $getanswervalue];
      Session::push('answer', $getsession);
  
      // return response()-&gt;json(['qid'=&gt;$getidvalue,'answer'=&gt;$getanswervalue]);
  
      $score = array_sum(Session::get("getscoresession"));
  
      // return view('submitquestion',compact('score'));
  
      return view('submitquestion', ['score' =&gt; $score]);
  }
  </code></pre>
  
  <p>Blade part :</p>
  
  
  
      You have submitted quiz and your score is : {{ $score  }}>
  
  
  
  LOGOUT