我正在使用 Laravel 开发一个社交媒体项目。我需要为关注者和关注者提供定制的 API。因此,我想在用户表与关注者和关注表之间建立关系。我查看了很多资源,但感到困惑。谁能帮我处理人际关系?
楷模
用户: id,用户名,电子邮件,密码
关注: id、user_id、follow_id(user_id)
追随者: id、user_id、follower_id(user_id)
API 网址: http://localhost/api/follows/user_id/1
跟随控制器
public function user_follow($user_id)
{
$user_find = Follows::where("user_id", "=", $user_id)->get();
return response()->json($user_find, 201);
}
输出
[
{
"id": 4,
"user_id": 1,
"follow_id": 4,
"created_at": "2020-03-23T15:11:48.000000Z",
"updated_at": "2020-12-11T11:10:10.000000Z"
},
{
"id": 5,
"user_id": 1,
"follow_id": 1,
"created_at": "2012-08-30T20:16:51.000000Z",
"updated_at": "2020-12-11T11:10:10.000000Z"
}
]
根据用户请求带来相关关注者的 API。但是在这里,我想给相关用户的附加用户信息,我该怎么做呢?