Open sidebar
$validator = \Validator::make($request->all(), $this->rules); if ($validator->fails()) { return response()->json($validator->errors(), 400); } $survey = new Survey($request->only('title','description','user_id','status')); $survey->save(); if($request->questions){ $questionsForSave = []; foreach ($request->questions as $question) { $questionsForSave[] = new SurveyQuestion($question); } $survey->questions()->saveMany($questionsForSave); } return response()->json($survey, 201);
Close sidebar
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting