AntonioNicasio's avatar

Help! Saving a multiple rows of a foreign key

hello guys I have an issue traying saving a multiple data of a form, I can save the data just in a singular (Example:) I have a poll and in that pool want to add more members not just one, by the way saving data for want member works properly this member is for a foreignkey

$integrante_id

who cloud do to save a multiple members for that poll, I add a member with jquery clicking a button and that display a a new form inputs for that new member I try to follow the documentacion with not success.

I just can save one member at the moment

this is my controller

public function store(EncuestaRequest $request){

    // Image Upload
    $file = $request->file('image');
    $file_count = count($file);
    $fileupload = 0; 
    $name = 'imagen_' . time() . '.' . $file->getClientOriginalExtension();
    $path = public_path() . '/uploads';
    $file->move($path, $name);

    $encuestas = new Encuesta($request->all());
    $encuestas->save();
    //dd($encuestas);
    
    // Saving Integrante 
    $integrantes = new Integrante();
    $integrantes->nombres = $request->nombres;
    $integrantes->curp = $request->curp;
    $integrantes->parentesco = $request->parentesco;
    $integrantes->fecha_nacimiento = $request->fecha_nacimiento;
    $integrantes->genero = $request->genero;
    $integrantes->estado_nacimiento = $request->estado_nacimiento;
    $integrantes->encuesta()->associate($encuestas);
    $integrantes->save();
       
     
    // Saving Image   
    $image = new Image();
    $image->name = $name;
    $image->encuesta()->associate($encuestas);
    $image->save();

    
    return redirect('encuesta');
}
0 likes
1 reply
jlrdw's avatar

Sorry, I don't understand everything. But you may be better off just doing one at a time anyway.

Please or to participate in this conversation.