Get id of a form created previously to relate it to another LARAVEL 5.5 table

1

I write here because I have this doubt, maybe it is silly but I have not managed to solve it ..

I have two related tables REVISION and RISKS , the relationship is 1 review has many risks , and 1 risk belongs to 1 revision , I already made the relation in the models and in the bd, then in the form I send it and I save the data, then in another tab I have a button that allows me to register a risk associated with this created revision , but I do not know how to get the revision id created previously , each form I have in a different controller since apart from that relationship there are a series of options but they are in RevisionController and RiskController respectively. I do not know if I was very clear, I hope you can help me. Thanks !!

    
asked by Luis Izquierdo 29.06.2018 в 15:52
source

1 answer

0

Something like this you need to do to save the revision id.

$model = New Revision;
$model->texto = $request->get('data');
if($model->save()){
    $riesgo = New Riesgo;
    $riesgo->id_revision = $model->id;
    $riesgo->data = $request->get('data');
    if($riesgo->save()){
        return true;
    }
}
return false;
    
answered by 29.06.2018 в 19:54