【发布时间】:2019-04-07 09:26:20
【问题描述】:
我正在尝试使用Laravel eloquent关系创建社区关注系统,我无法解决问题,请帮助
基本上,我正在尝试创建基于社区(例如:商业与专业、健康与保健、科学与技术等)的活动系统。
它给了我以下错误
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'acp_db.community_users' doesn't exist (SQL: select * from `community_users` where `community_users`.`id` = 8 limit 1) in file /Users/muhammadowais/mowais/academics-provider/website/working/acpapi/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664
为了通过 Id 获得社区的关注者,我创建了以下表格
1) 用户
2) event_categories(可以说是社区)
3) community_user (user_id, community_id)
控制器
public function communityBySlug($slug){
$eventCategory = EventCategories::where(['slug' => $slug])->first();
$eventCategoryId = $eventCategory->id;
// Getting users by community id
$users = CommunityUsers::find(8)->users();
return Response::json(
[
'data' => $eventCategory,
'community_followers' => $users
]
);
}
模型:社区用户
class CommunityUsers extends Model
{
protected $fillable = ['community_id', 'user_id'];
protected $guarded = [];
public function Users(){
return $this->belongsToMany(User::class, 'users');
}
}
【问题讨论】:
标签: laravel laravel-5 eloquent-relationship