我正在尝试使用 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) 社区_用户(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');
}
}