Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $question = new Question();
     // set the question's data from the form data
     $question->title = $request->title;
     $question->description = $request->description;
     $question->code = $request->code;
     $question->user_id = Auth::user()->id;
     // create the new question in the database
     if (!$question->save()) {
         $errors = $question->getErrors();
         // redirect back to the create page
         // and pass along the errors
         return redirect()->action('QuestionController@create')->with('errors', $errors)->withInput();
     }
     // success!
     // establish language relationships
     if ($request->language_id) {
         $question->languages()->sync($request->language_id);
     }
     return redirect()->action('QuestionController@index')->with('message', '<div class="alert alert-success">Question created successfully!</div>');
 }