I'm developing a system and I came across the following situation:
I need to insert the data first into the 'person' table, retrieve the last 'person_id', and then insert the data into the 'provider' table everything in the store method, look below what I have up to now;
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 something is missing but I'm not sure what, when I run the code the table person receives the data, but the supplier table, receives nothing and returns the following error:
SQLSTATE [23502]: Not null violation: 7 ERROR: null value in column "staple_info" violates non-null constraint DETAIL: Record that failed contains (13, 36, null). (SQL: insert into "provider" ("people_id") values (36) returning "provider_id")
Does anyone have a suggestion?