请注意,当在foreach循环之外时,该变量正在打印null。当我在循环中添加它时,它打印了正确的东西。如何在视图上显示记录?
public function show($questionId)
{
// $answerID = array();
$newAnswers = null;
// $questions = Question::select('AnswersID','surname')->where('id', 1)->get();
$questions = DB::table('question')->where('id', $questionId)->pluck('AnswersID');
$values = explode(" ", $questions);
print_r($values);
foreach ($values as $answers) {
$newAnswers = DB::table('answer')->where('AnswerShortID', $answers)->get();
}
return (View::make("charts/qanswers/index", compact('newAnswers')));
}