我的代码中有什么问题,我在服务器上遇到错误,而在本地服务器上工作正常。
数据也在数据库中传递。但得到错误
一个测验,问题有多种选择: 我遇到以下错误
(1/1) ErrorException
Creating default object from empty value
public function update(Request $request, $id)
{
$this->validate($request, [
'question' => 'required|max:255',
'score' => 'required|integer',
]);
$chapter_id = $request->chapter_id;
$questions = Question::orderBy('id', 'asc')->paginate(25);
$question = Question::findOrFail($id);
$question -> question = $request -> question;
$question -> explanation = $request -> explanation;
$question -> score = $request -> score;
$question -> chapter_id = $chapter_id;
$question -> sponsor_id = $request->sponsor_id;
$question -> admin_id = Auth::guard('admin')->id();
// Image Processing
if($request->hasFile('image')){
$image = $request->file('image');
$filename = time() . '.' . $image->getClientOriginalExtension();
$location = storage_path('/app/public/images/' . $filename);
Image::make($image)->resize(800, 400)->save($location);
$question -> question_image = $filename;
}
// Getting Next ID
$question->save();
// $option = New QuestionsOption;
// $que = Question::all();
for($a=1; $a<=5; $a++){
$option = 'text_option_'. $a ;
$option_id = 'option_id'. $a;
$question_option = QuestionsOption::findOrFail($request ->$option_id);
问题在下面的行中。
$question_option -> question_text = $request -> $option;
$question_option -> correct = $request->input('correct_' . $a);
$question_option->save();
}
if($question->save()){
return view('admin.questions.index', compact('questions', 'chapter_id'));
} else{
Session::flash('Sorry a problem occurred while adding Question');
return redirect()->route('questions.create');
}
}