Reputation: 1513
I want to insert some value in db, but I get an error, and I am not sure why.
Trying to get property 'lkp_relationship_correlation' of non-object**
$person = new Person();
foreach ($request->relationship_values as $item) {
$relationship = new Relationship();
$relationship->fill([
'lkp_relationship_correlation_id' => $item->lkp_relationship_correlation,
'relative_fullname' => $item->relatives_surname,
'relative_surname' => $item->relatives_full_name,
'relative_id' => 3,
]);
$relationship->person()->associate($person)->save();
};
public function person()
{
return $this->hasMany(Person::class, 'person_id');
}
public function relationship()
{
return $this->belongsTo(Relationship::class);
}
dd($item);
array:3 [ "lkp_relationship_correlation" => 11 "relatives_surname" => "Simona" "relatives_full_name" => "Simona Arabu" ]
Upvotes: 0
Views: 45
Reputation: 2095
Given that $item
is an array, you can't do this:
$item->lkp_relationship_correlation
You can access the lkp_relationship_correlation
value like:
$item['lkp_relationship_correlation']
Upvotes: 2