I am struggling to use laravel push()
function
My Code is here:
$company = new Company(array('name' => 'Company 1'));
$company->persons[] = new Person(array('name' => 'Company 1 Person 1', 'mobile' => 12345));
$company->persons[] = new Person(array('name' => 'Company 1 Person 2', 'mobile' => 112233));
$company->push();
When it gets stored:
Company gets stored well, but for company persons, it stores company_id
to 0
Larave Documentations says:
Sometimes you may wish to save not only a model, but also all of its relationships. To do so, you may use the push method:
$user->push();
what is wrong?
push()
before but it seems like maybe you aren't using it correctly. The docs don't give much mention to it. See this question – Jared Eitnier