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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -