Laravel | Fill in 2 MySQL tables at the same time

0

I am working on an application in Laravel, and I have 3 MySQL tables: ( role-users-permissions_users ), I need to know how to fill 2 tables in a single register ie the user registers, a id is saved as a primary in the table " users ", and that id is a foreign key in the table " permissions_users strong> ", but I do not know how to fill in the table" permissions "with the id of the table" user ", I do not know if they understood me . Basically I want to fill 2 tables in a single register, any help will be welcome!

    
asked by gburu98 02.07.2016 в 19:24
source

1 answer

1

Basically if you are using Eloquent  There is a function to return the id created in the insertion, an example would be more or less this

$empleados = new Empleados();
//aqui metes lo registros que estes guardando para tu tabla
$empleados->save();
$id = empleados->id;//este en el caso que tu llave primaria se llame id

to save in the other table you just have to use the variable $id and already with that you do the other insertion to the table privileges

    
answered by 02.07.2016 / 21:35
source