【发布时间】:2016-06-30 18:45:54
【问题描述】:
在数据库中我有以下结构
编号 | following_id | follow_id 1 | 3 | 1 2 | 2 | 1我有用户模型,它看起来像这样
公共函数 userFollows() { return $this->belongsToMany('Diskourse\Models\User','followers','following_id','followed_id');
}
public function userIsFollowed()
{
return $this->belongsToMany('Diskourse\Models\User','followers','followed_id','following_id');
}
public function followers()
{
return $this->userIsFollowed->merge($this->userFollows);
}
最后的视图看起来像这样
<h4>Followers</h4>
@if(!$user->followers()->count())
<p>No followers</p>
@endif
@foreach($user->followers() as $follower)
@include('user/partials/userblock')
@endforeach
</div>
</div>
如果它正常工作,它应该将用户 3 和 2 显示为 1 的追随者。相反,当前用户配置文件块显示两次。请帮忙!!!!
【问题讨论】:
标签: laravel-5