我已经安装了用于关注管理的包,但我想更多地将其集成到我的应用程序中,以便只显示关注您的用户的内容,例如instagram,以便更好地了解我们。
https://github.com/overtrue/laravel-follow#api
我现在的代码是这样的,怎么集成?
$items = Items::whereHas('category', function ($query) {
$query->where('status', 1); // only where the category it belongs to is active
})->whereHas('user', function ($query) {
$query->where('access', 1); // only by users with a public profile
})->where('visible', 1)
->where('status', 1)
->orderByDesc('id')
->paginate(25);
表: 用户、项目、User_follower
答案 0 :(得分:0)
我留下了我正在尝试做的事情的小更新,但有错误:
Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select count(*) as aggregate from `items` where exists (select * from `users` where `items`.`user_id` = `users`.`id` and exists (select * from `users` as `laravel_reserved_0` inner join `user_follower` on `laravel_reserved_0`.`id` = `user_follower`.`following_id` where `users`.`id` = `user_follower`.`follower_id` and `id` = 1)) and exists (select * from `categories` where `items`.`category_id` = `categories`.`id` and `status` = 1) and exists (select * from `users` where `items`.`user_id` = `users`.`id` and `access` = 1) and `visible` = 1 and `status` = 1)
$items = Items::whereHas('user.followings', function ($query) use ($user_id) {
$query->where('id', $user_id);
})->whereHas('category', function ($query) {
$query->where('status', 1); // only where the category it belongs to is active
})->whereHas('user', function ($query) {
$query->where('access', 1); // only by users with a public profile
})->where('visible', 1)
->where('status', 1)
->orderByDesc('id')
->paginate(25);
public function user(){
return $this->belongsTo(User::class);
}
public function followings(){
return $this->belongsTo(Follow::class);
}