0

What is issue in my code i am getting error on server while its working fine on local server.

data also passing in database. but getting given error

its a quiz where question have multiple choices: i am getting following error

(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);

Problem is there in below line.

        $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');
      }
    }
Tridev Shrestha
  • 447
  • 7
  • 21
Hassan Raza
  • 1,454
  • 2
  • 13
  • 17
  • This might be helpful, your server may have different error reporting rules from your local environment: https://stackoverflow.com/questions/8900701/creating-default-object-from-empty-value-in-php – techcyclist Feb 23 '19 at 23:32
  • It Might be helpful. i will contact with my hosting company. – Hassan Raza Feb 23 '19 at 23:36
  • This is not hosting, this is to do with your code, What line does it tell you the error is from within the code? For example: line 228 ?? Can you post the full controller? The problem is with the data being sent to the update method. – Birdy Feb 23 '19 at 23:53
  • Still errors :( – Hassan Raza Feb 24 '19 at 09:29
  • @birdy i have posted complete update method. getting error in line#174. i commented on line where getting error. Please Help me to resolve. – Hassan Raza Feb 24 '19 at 09:31
  • 1
    Before for($a=1; $a<=5; $a++) or on line 173 do this: dd($request); or dd(request()); This will show you the exact data being passed at this point because somewhere along the lines there is a data issue. You should be able to debug by seeing the data. – Birdy Feb 24 '19 at 16:55

0 Answers0