本文介绍了如何将更多数据添加到Laravel的auth()-> user()对象及其关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的user模型具有名为person_id的外键引用,该引用引用了我的people表中的单个person.

My user model has foreign key reference called person_id that refers to a single person in my people table.

我死后&转储我得到的经过身份验证的用户(dd(auth()->user())):

When I die & dump the authenticated user (dd(auth()->user())) I get:

{"id":1,"email":"[email protected]","is_enabled":1,"person_id":3,"created_at":"2017-12-12 10:04:55","updated_at":"2017-12-12 10:04:55","deleted_at":null}

我可以通过调用auth()->user()->person来访问人,但这是原始模型.人员的演示者未应用到该演示者,因此我无法在身份验证用户的人员上调用演示者方法,因为我不知道在哪里调用我的演示者.

I can access person by calling auth()->user()->person however it's a raw model. Person's Presenter is not applied to it hence I can't call presenter methods on auth user's person because I don't know where to call my presenter.

调整auth()->user对象及其关系的最佳位置在哪里?

Where is the best place to tune up auth()->user object and it's relationships so I can apply specific patterns on them?

谢谢,Laravel 5.5.21.

Thanks,Laravel 5.5.21.

推荐答案

使用 load() 方法:

auth()->user()->load('relationship');

这篇关于如何将更多数据添加到Laravel的auth()-> user()对象及其关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 00:32