Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CodeFox's avatar

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?

0 likes
3 replies
CodeFox's avatar

Can't believe I missed that. Working fine, thanks! :)

jlrdw's avatar

If answered please show answered.

Please or to participate in this conversation.