Pass two variables to a method in laravel

1

Help I'm stuck in a part of my project, I'm doing an intranet for a Lyceum. The subject is that I want to place an "Observation" to a Student, for this I need the "id" of the Student, the "id" of the Subject, and the "id" of the Teacher that is Authenticated. In a hearing I have all the students of a subject.

By selecting add behavior (the red icon on the right) I receive the "id" of the student and the subject in this controller

public function agregarAnotacion($id, $id)
{   
    $alumno = Alumno::find($id);

    $asignatura = Asignatura::find($id);

    return view('agregaranotacion')->with('alumno',$alumno)->with('asignatura',$asignatura);
}

The "id" of the teacher will be obtained with the Auth. But I do not know how I can store this in my database since the create () and store () method of laravel comes without variables. I have to create another method to store them? or can I use the same create (), store ()? and if so, how would it be? thanks in advance for your answers

    
asked by Edgardo Escobar 08.03.2017 в 01:09
source

1 answer

2


When you click on add behavior, you could have a form where it is hidden fields:

- student id - subject id - teacher's id. - observation

This you send in the form






 Lo recibis de la siguiente manera.

public function store(Request $request){
 // obtenes los datos enviados
 $idAlumno = $request->id_alumno;
 $idAsignatura = $request->id_asignatura;
 $idProfesor = $request->id_profesor;
 $Obseervacion = $request->observacion;

creas un array con los valores obtenidos, la columna de la izquierda son los
nombre de tus campos de la base de datos y la derecha los valores obtenidos

 $dataSaveObservacion = array(
   'id_alumno' => $idAlumno,
   'id_asignatura' => $idAsignatura,
   'id_profesor' => $idProfesor,
   'observacion' => $Obseervacion ,
  );

 llamas tu tabla
$AddObservacion = new Observaciones($dataSaveObservacion );  

Guardas
  $AddObservacion->save();


}
    
answered by 08.03.2017 / 02:07
source