I have 2 classes in Laravel
class Company
{
public function people()
{
return $this->hasMany('Person');
}
}
class Person
{
public function company()
{
return $this->belongsTo('Company');
}
}
Now in another class, I am creating a person object and setting company_id with a defined variable $companyId
.
$person = new Person;
$person->company_id = $companyId; //Code not executing after it.
$person->save();
When I am setting $companyId in $person, it is just being in recursive call and never come back.
I have also tried this code as well, but no luck, again, it is stuck somewhere and never save.
$company = Company::find($companyId);
$person = new Person;
$company->people()->save($person); // Never execute this
Please provide some sight, what wrong I am doing, I googled for this but not found which resolve this.
- EDIT *
This app was created and maintain in laravel 4.2 and there it is working fine, but while upgrading this to laravel 5.7, this is giving issue here.
Thanks