1
I am developing a system and came across the following situation:
I need to enter the data first in the 'person' table, retrieve the last 'id_person' and then insert the data in the 'provider' table all in the method store, note below what I have so far;
public function store(Request $request) {
//capturar todos os dados digitados
$dadosPessoa = $request->all ();
//realizar insert via Eloquent e retornar o id_pessoa
$id_pessoa = Pessoa::create ( $dadosPessoa )->id_pessoa;
//id_pessoa na tabela pessoa é id_pessoa na tabela fornecedor
$input ['id_pessoa'] = $id_pessoa;
Fornecedor::create ($input);
}
I know there’s something missing but I’m not sure what, when I execute the code to the table person receives the data, but the table supplier, receives nothing and returns the following error:
SQLSTATE[23502]: Not null Violation: 7 ERROR: null value in column "enrolled" violates the non-null restriction DETAIL: Registration that failed contains (13, 36, null). (SQL: Insert into "vendor" ("id_person") values (36) returning "id_supplier")
Someone has a suggestion?
You’re not passing anything on to Eloquent so he knows what he should have in the Vendor table. Just like you did the $request->all() and passed to the Pessoa::create... has to do for the supplier. Now, about the supplier id, I don’t understand what you really want... every supplier belongs to one person? How’s your model? Post your model here to help you better. If so, and if you have made the connections on the model, it will be very easy! I await details. Abs
– Evert