我正在建立一个带有帖子赞的论坛系统,但是由于某种原因,帖子赞的关系不会返回任何数据。
我曾尝试在没有资源的情况下加载数据,并包含在('all_likes')中,但这仍然不会返回数据。
我的获取帖子方法:
write()
我的论坛帖子资源:
ConnectedThread
我的论坛帖子模型:
// At this point you have one thread (there may be more,
// but suppose it's only one).
// The thread is executing the code below.
ConnectedThread connectedThread = new ConnectedThread(socket);
connectedThread.start();
// Now you have two threads running simultaneously.
// The new thread is doing whatever the run() method defined in
// ConnectedThread,
// that is that infinite loop with read() calls.
// But this thread goes on.
connectedThread.write();
// The write() call above is executed in this thread,
// which has nothing to do with
// the run() defined in ConnectedThread.
单击“喜欢”按钮后,用户ID和帖子ID将添加到post_likes数据库中。然后,在加载视图时,将显示所有论坛帖子,包括该帖子的点赞关系数据。
我得到的结果是:
public function getPosts($id)
{
$response = array();
$response['posts'] = ForumPostResource::collection(ForumPost::where('thread_id', $id)->get());
return $response;
}
这应该返回1条类似结果的帖子,因为我的数据库看起来像这样:
id | user_id | post_id
1 | 1501 | 14
答案 0 :(得分:0)
我忽略了它正在调用App\PostLike
并且外键和本地键顺序错误的事实。
方法定义为:
public function hasMany($related, $foreignKey = null, $localKey = null)