php - Laravel 5 recursion in models -
i have 2 models, contactinformation , user model. user models hasmany contact informations contactinformation belongs user. app\user.php looks 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 try access contactinformation in controller so:
$contact_gegevens = auth::user()->contactgegevens();
it gets recursive records. (duh). question is, how can avoid without losing functionality of having user relation in contact information or losting contact information in user model?
Comments
Post a Comment