Level 75
Oct 11, 2017
3
Level 4
Save data cleanly
Hey
Suppose I am wanting to take data from a form and save it in a clean way to two separate models. What is the best way to do so?
For example, I have the following models: Quiz and Respondent, and the controller is QuizController.
I'm passing the data to QuizController and can easily save the data to the Quiz model, but I'm taking in several respondents from the form as an array. These will then be saved to a Respondent model.
My (pseudo)code looks like this:
$quiz = new Quiz;
$quiz->name = $request->name;
$quiz->save;
Respondents::insert($request->respondents);
Surely there is a better way of doing this?
Please or to participate in this conversation.