app/Http/Controllers/QuestionController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $question = new Question();
        $question->club_id = $request->club_id;
        $question->question = $request->question;
        $question->show = true;
        $question->answer = $request->answer;
        $result_1 = $question->save();
        foreach($request->answers as $answer_item){
            $answer = new Answer();
            $answer->question_id = $question->id;
            $answer->answer = $answer_item;
            $result_2 = $answer->save();
        }
        if($result_1 && $result_2){
            $error = [1,'สร้างสำเร็จ'];
        }else{
            $error = [0,'เกิดข้อผิดพลาดบางอย่าง โปรดติดต่อแอดมิน'];
        }
        return redirect()->back()->with(['result'=>$error[0],'text'=>$error[1]]);
    }
public function store ( Request $ request ) { $ question = new Question ( ) ; $ question -> club_id = $ request -> club_id ; $ question -> question = $ request -> question ; $ question -> show = true ; $ question -> answer = $ request -> answer ; $ result_1 = $ question -> save ( ) ; foreach ( $ request -> answers as $ answer_item ) { $ answer = new Answer ( ) ; $ answer -> question_id = $ question -> id ; $ answer -> answer = $ answer_item ; $ result_2 = $ answer -> save ( ) ; } if ( $ result_1 && $ result_2 ) { $ error = [ 1 , 'สร้างสำเร็จ']; } else { $ error = [ 0 , 'เกิดข้อผิดพลาดบางอย่าง โปรดติดต่อแอดมิน']; } return redirect ( ) -> back ( ) -> with ( [ 'result' => $ error [ 0 ] , 'text' => $ error [ 1 ] ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//