Laravel, foreign key

0

I have a table of students and another table of documents, they have a ratio of 1: 1 How can I insert a record in a document in which I am asked for the student's id? to bring me the id of a student that already exists and insert with that id.

    
asked by Estefania 17.10.2017 в 05:12
source

1 answer

0

Let's see if I understood your question. You get the student ID according to a condition, for example:

$id_alumno = Alumno::where("nombre","=","pepito")->value("id_alumno");

Then insert the row of the document:

$documento = new Documento();
$documento->id_alumno = $id_alumno;
$documento->save();
    
answered by 17.10.2017 в 05:20