app/Http/Controllers/QuestionsController.php
/**
     * Store a newly created Question in storage.
     *
     * @param  \App\Http\Requests\StoreQuestionsRequest  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created Question in storage.
Store a newly created Question in storage .
public function store(Request $request)
    {
        if($request->isMethod('post')) {
            $data = $request->all();
            $question = Question::create($request->all());
            for ($q=1; $q <= 4; $q++) {
                $option = $request->input('option_text_' . $q, '');
                if ($option != '') {
                    QuestionsOption::create([
                        'question_id' => $question->question_id,
                        'option_text' => $option,
                        'correct' => $request->input('correct_' . $q)
                    ]);
                }
            }
            return redirect()->route('questions.index')->with('flash_message_success','Successfully Added');
        }
    }
public function store ( Request $ request ) { if ( $ request -> isMethod ( 'post' ) ) { $ data = $ request -> all ( ) ; $ question = Question :: create ( $ request -> all ( ) ) ; for ( $ q = 1 ; $ q <= 4 ; $ q ++ ) { $ option = $ request -> input ( 'option_text_' . $ q , '' ) ; if ( $ option != '' ) { QuestionsOption :: create ( [ 'question_id' => $ question -> question_id , 'option_text' => $ option , 'correct' => $ request -> input ( 'correct_' . $ q ) ] ) ; } } return redirect ( ) -> route ( 'questions.index' ) -> with ( 'flash_message_success' , 'Successfully Added' ) ; } }
Store a newly created Question in storage.
Store a newly created Question in storage .
// dd($data); // $question->exams()->sync(array_filter((array)$request->input('exams'))); // dd($option); // dd($question);