Register N for 1 and N for N?

0

How do I sign up for a relationship 1 for N and N for M , I am doing this but :

$endereco = new endereco;
$endereco->complemento = $request->complemento;
$endereco->logradouro = $request->logradouro;
$endereco->bairro = $request->bairro;
$endereco->cidade = $request->cidade;
$endereco->estado = $request->estado;
$endereco->cep = $request->cep;
$endereco->save();   

$civil = new civil;
$civil->nome = $request->nome;
$civil->cpf = $request->cpf;
$civil->matricula = $request->matricula;
$civil->data_nascimento = $request->data_nascimento;
$civil->pai = $request->pai;
$civil->mae = $request->mae;
$civil->situacao = $request->situacao;
$civil->sexo = $request->sexo;
$civil->matricula = $request->matricula;
$civil->estado_civil = $request->estado_civil;
$endereco->civil()->save($civil);    
    
asked by anonymous 18.12.2017 / 20:55

1 answer

0

If I'm not in error, the address key is on the civilian side. The entity sequence is correct, but I see a problem in the line: $endereco->civil()->save($civil); . If you want to "set" the address code, something like $civil->endereco_id = $endereco->id; and finally $civil->save();

I would advise you to see about Eloquent Relationships at link

    
18.12.2017 / 21:25