I have two models as follows.
Tier Model:
public function contact(){
return $this->belongsTo(ContactAdresse::class,"contact_adresse_id");
}
ContactAdresse Model:
public function tiers(){
return $this->hasMany(Tier::class);
}
Now I’m trying to retrieve the Tier associated with the Contact using this code:
{{ $ContactAdresse->tier->nom_prenoms}}
I have the following error.
Attempt to read property "nom_prenoms" on null
Does anyone have an idea, please?
>Solution :
If you want to access the nom_prenoms property of each Tier associated with a ContactAdresse, you can loop through the tiers collection like this.
@foreach($ContactAdresse->tiers as $tier)
{{ $tier->nom_prenoms }}
@endforeach