File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,20 @@ public function choices()
1717 return $ this ->hasMany ('DivineOmega\LaravelMultipleChoice\Models\Choice ' );
1818 }
1919
20- public function responseItem ()
20+ public function responseItems ()
2121 {
2222 return $ this ->hasMany ('DivineOmega\LaravelMultipleChoice\Models\ResponseItem ' );
2323 }
2424
25- public function render ()
25+ public function render (Response $ response = null )
2626 {
27- $ view = View::make ('lmc::question ' , ['question ' => $ this ]);
27+ $ selectedChoice = null ;
28+
29+ if ($ response ) {
30+ $ selectedChoice = $ this ->responseItems ()->where ('response_id ' , $ response ->id )->first ();
31+ }
32+
33+ $ view = View::make ('lmc::question ' , ['question ' => $ this , 'selectedChoice ' => $ selectedChoice ]);
2834 return $ view ->render ();
2935 }
3036}
Original file line number Diff line number Diff line change 99 @foreach ($question -> choices as $choice )
1010 <div class =" lmc-choice" id =" lmc-choice-{{ $choice -> id } }" >
1111 <input type =" radio" class =" lmc-choice-input" id =" lmc-choice-input-{{ $choice -> id } }" name =" lmc-question-input-{{ $question -> id } }" value =" {{ $choice -> id } }" >
12- <label class =" lmc-choice-label" id =" lmc-choice-label-{{ $choice -> id } }" for =" lmc-choice-input-{{ $choice -> id } }" >
12+ <label class =" lmc-choice-label" id =" lmc-choice-label-{{ $choice -> id } }" for =" lmc-choice-input-{{ $choice -> id } }" {{ $choice -> id == $selectedChoice -> id ? ' checked ' : ' ' } } >
1313 <span class =" lmc-choice-text" id =" lmc-choice-text-{{ $choice -> id } }" >{{ $choice -> text } } </span >
1414 <span class =" lmc-choice-description" id =" lmc-choice-description-{{ $choice -> id } }" >{{ $choice -> description } } </span >
1515 </label >
You can’t perform that action at this time.
0 commit comments