I have 2 models, a contactinformation and a user model. The user models hasMany contact informations but the contactinformation also belongs to a user. App\User.php looks like this:
public function contactgegevens(){
return $this->hasMany('App\Contactgegevens', 'id', 'user_id');
}
And App\Contactgegevens (contact information in Dutch) looks like:
public function user(){
$this->belongsTo('App\User', 'user_id', 'id');
}
Now when I try to access the contactinformation in a controller like so:
$contact_gegevens = Auth::user()->contactgegevens();
It gets recursive records. (duh). Now my question is, how can I avoid this without losing the functionality of having a User relation in my contact information or losting the contact information in the user model?