Talk buddy, all right? Come on!
Apparently the case is of hasOne relationship... as well?
Your suppliers table works with n:1 relationship for addresses.
Fixing that in your model you have defined as hasMany, that free translation is "contains several". Ie, fornecedores contém vários endereços. Which according to your schema is not quite so, in it the provider contains only ONE address, as it works with FK direct to addresses.
The eloquent of the alternatives to working with relationships, in a way practically papaya with sugar.
$fornecedor = new Fornecedor();
$fornecedor->cnpj = $request->get('cnpj');
$fornecedor->razao_social = $request->get('razao_social');
$fornecedor->endereco->logradouro = $request->get('logradouro');
$fornecedor->endereco->bairro = $request->get('bairro');
$fornecedor->endereco->cep = $request->get('cep');
$fornecedor->push();
In this example "push" will occur. When saving the provider it will save the address and already do the link for you.
You can check in the manual this method: http://laravel.com/docs/4.2/eloquent#relationships
Remembering that you need to make the relationship of: fornecedores belongsTo enderecos
The push it checks every relation and performs the commands, if you do not like the use of it, you can choose to associate.
Good, doubts of a touch!
The problem is getting the
idaddress and write to the supplier?– rray
@rray, too. All data is populated in the vendor view. The action of this form goes to the vendor controller. I want to separate personal data and address, record each in their respective table and then make the relationship.
– buback