Ad
Insert Value In Table Relationship Laravel
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" ]
Ad
Answer
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']
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad