Wakanda's avatar
Level 10

createOrUpdate Many

Hi Devs,

I have a question model and that has many questions and the create method works fine as I create the questions and many answers

store method

 $question = $practise->questions()->create($request['question']);
$question->answers()->createMany($request['answers']);

update method

$question->update($request['question']);

$question->answers()->updateOrCreate($request['answers']);  // not working since am trying to update many

my request returns

"question" => array:1 [▼
    "body" => "<div>Qui omnis qui esse c.</div>"
  ]
"answers" => array:4 [▼
    1 => array:3 [▼
      "body" => "Quia tenetur non ius"
      "order" => "Aut quaerat eaque vo"
      "is_correct" => "0"
    ]
    2 => array:3 [▶]
    3 => array:3 [▶]
    4 => array:3 [▶]
  ]

The question is how do I update or create many?

0 likes
1 reply

Please or to participate in this conversation.