I have two Entries and Company tables that have a 1 to 1 relationship
I have a form that the user selects if it is pf or pj, if it is pj it opens the options to save the company.
But when I give the $ company- > save () it generates an error because it is returning an array. Can anyone help me?
follow the code!
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();
}
}