1
I have two tables Entries and Company that have relationship from 1 to 1
I have a form that the user selects if it is pf or pj, if it is pj opens the options to save the company.
However, when I give $company->save() it generates an error because it is returning in an array. Can someone help me?
follows the code!
https://gist.github.com/adgole/9679025
Model Company
<?php
class Company extends Eloquent {
protected $table = 'Company';
protected $softDelete = true;
protected $guarded = array('id');
public function Company() {
return $this->belongsTo('Entry', 'entries_id');
}
}
Model Entry
<?php
class Entry extends Eloquent {
protected $table = 'entries';
protected $softDelete = true;
protected $guarded = array('id');
public static $rules = array(
'name' => 'required|min:3|max:255',
);
public function company() {
return $this->hasOne('Company', 'entries_id');
}
public function payments() {
return $this->hasMany('Payment', 'entries_id');
}
public function getStatusAttribute()
{
// Status do ultimo pagamento
$last_payment = $this->payments()->orderBy('updated_at', 'DESC')->first();
if ($last_payment) {
return $last_payment->status;
}
}
}
Entrycontroller
public function store()
{
$entry = new \Entry(\Input::except(
'company_name',
'company_cnpj',
'company_cep',
'company_address',
'company_number',
'company_complement',
'company_neighborhood',
'company_city',
'company_state'
));
if ($entry->save()) {
$company = new \Company();
$company = \Input::only(
'company_name',
'company_cnpj',
'company_cep',
'company_address',
'company_number',
'company_complement',
'company_neighborhood',
'company_city',
'company_state'
);
dd($company);
$company->entries_id = $entry->id;
$company->save();
}
}