Laravel eloquent model save error -
i getting error when trying save eloquent model follows: argument 1 passed illuminate\database\eloquent\relations\hasoneormany::save() must instance of illuminate\database\eloquent\model, string given,
i have model question hasmany answeroption on other side answeroption belongsto question
i have model questionrevision hasmany questionrevisionansweroption on other side questionrevisionansweroption belongsto questionrevision
basically want copy answeroptions question have retrieved new instance of questionrevision (as questionrevisionansweroptions).
i have saved new questionrevision ($origrev) successfully. trying add questionrevisionansweroptions go it. error argument 1 passed illuminate\database\eloquent\relations\hasoneormany::save() must instance of illuminate\database\eloquent\model, string given,
i have tried saving questionrevisionansweroptions @ once array using savemany , individually same error either way.
here relevant code:
$original = question::findorfail($qid); // find original question $origrev = new questionrevision(); // copy stuff original origrev $origrev->save(); // works here // answeroptions original , copy $origrev foreach ($original->answeroptions $ao) { $answeroption = new questionrevisionansweroption(['answer_text'=> $ao->answer_text, 'answer_explanation' => $ao->answer_explanation, 'answer_option_id' => $ao->id, 'is_correct' => $ao->is_correct ]); $origrev->revisionansweroptions()->save($answeroption); //this line generates error. }
why getting error , how can correct it?
Comments
Post a Comment