我有一个默认表用户和相关表 user_details.
当用户进行身份验证时,它会从用户表中检索数据并可供全局对象使用:
Auth::user()
如何使用相关表中的数据扩展 Auth::user() user_details
?
原因是在每个页面中显示有关经过身份验证的用户的完整信息(在标题处)
如果我正确理解了这个问题,则不需要扩展 Auth,只需扩展您的 User 模型。你可以在你的 User 模型上使用几个不同的助手,->hasOne、->belongsTo 等(假设你有一个 user_details 模型),剩下的应该由 eloquent 来完成。
https://laravel.com/docs/master/eloquent-relationships
编辑:您可以向用户模型添加访问器。所以,在你的 app\User.php
public function getCustomAttribute()
{
return 'Custom Attribute';
}
你应该可以在任何地方使用类似的东西
Auth::user()->custom
https://laravel.com/docs/master/eloquent-mutators
(同样,我可能只是不理解你的问题)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句