php - Laravel 通过配置文件获取用户数据
问题描述
我有带有关注者/关注者的用户和个人资料模型。我想要的是在调用 Profile::followers 时将用户数据与 Profile 数据合并。现在我只检索配置文件数据。
所以我将 user() 添加到 Profile.php 中,这样我就可以调用 Profile::followers->user()... 但没有结果。following()
有人可以解释在调用函数时如何将用户与个人资料合并吗?
User.php 模型
public function following()
{
return $this->belongsToMany(Profile::class);
}
public function profile()
{
return $this->hasOne(Profile::class);
}
Profile.php 模型
public function followers()
{
return $this->belongsToMany(User::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
解决方案
推荐阅读
- sql - 在 SQL Server 中使用 charindex 从字符串中子串一个单词
- javascript - Mathjs'全局配置是只读的'?
- java - 如何在 Java 中控制 JDBC 连接的传出 IP?
- istio - publicIP 使用 istio-ingress 访问服务会出现 503 Servcie 不可用错误
- html - Bootstrap 4 在同一行中有六个盒子(响应式)?
- inheritance - 用物理或数学模型展示继承的包示例?
- bootstrap-4 - 悬停卡上的悬停按钮?
- sql-server - SQL Server 内存支持
- ios - 有没有办法在 SFSafariViewController 中传递 headerField 参数?
- ios - 当我更新翠鸟时,本地 gif 没有显示