Error saving data from a form to different tables

1

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!

link

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();
}

}
    
asked by anonymous 21.03.2014 / 04:38

1 answer

1

At line 74 you get the input data in array. That's why it does not work. In line 73 you create an object and on the bottom you assign an array.

Put the array in another variable and a $company->fill($input) for example.

    
21.03.2014 / 12:26