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

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -