fixed post count
This commit is contained in:
@@ -212,7 +212,7 @@ class ForumController extends Controller
|
|||||||
'parent' => $forum->parent_id ? "/api/forums/{$forum->parent_id}" : null,
|
'parent' => $forum->parent_id ? "/api/forums/{$forum->parent_id}" : null,
|
||||||
'position' => $forum->position,
|
'position' => $forum->position,
|
||||||
'threads_count' => $forum->threads_count ?? 0,
|
'threads_count' => $forum->threads_count ?? 0,
|
||||||
'posts_count' => $forum->posts_count ?? 0,
|
'posts_count' => ($forum->posts_count ?? 0) + ($forum->threads_count ?? 0),
|
||||||
'views_count' => (int) ($forum->threads_sum_views_count ?? 0),
|
'views_count' => (int) ($forum->threads_sum_views_count ?? 0),
|
||||||
'last_post_at' => $lastPost?->created_at?->toIso8601String(),
|
'last_post_at' => $lastPost?->created_at?->toIso8601String(),
|
||||||
'last_post_user_id' => $lastPost?->user_id,
|
'last_post_user_id' => $lastPost?->user_id,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class PortalController extends Controller
|
|||||||
->withoutTrashed()
|
->withoutTrashed()
|
||||||
->withCount('posts')
|
->withCount('posts')
|
||||||
->with([
|
->with([
|
||||||
'user' => fn ($query) => $query->withCount('posts')->with(['rank', 'roles']),
|
'user' => fn ($query) => $query->withCount(['posts', 'threads'])->with(['rank', 'roles']),
|
||||||
'latestPost.user.rank',
|
'latestPost.user.rank',
|
||||||
'latestPost.user.roles',
|
'latestPost.user.roles',
|
||||||
])
|
])
|
||||||
@@ -80,7 +80,7 @@ class PortalController extends Controller
|
|||||||
'parent' => $forum->parent_id ? "/api/forums/{$forum->parent_id}" : null,
|
'parent' => $forum->parent_id ? "/api/forums/{$forum->parent_id}" : null,
|
||||||
'position' => $forum->position,
|
'position' => $forum->position,
|
||||||
'threads_count' => $forum->threads_count ?? 0,
|
'threads_count' => $forum->threads_count ?? 0,
|
||||||
'posts_count' => $forum->posts_count ?? 0,
|
'posts_count' => ($forum->posts_count ?? 0) + ($forum->threads_count ?? 0),
|
||||||
'views_count' => (int) ($forum->threads_sum_views_count ?? 0),
|
'views_count' => (int) ($forum->threads_sum_views_count ?? 0),
|
||||||
'last_post_at' => $lastPost?->created_at?->toIso8601String(),
|
'last_post_at' => $lastPost?->created_at?->toIso8601String(),
|
||||||
'last_post_user_id' => $lastPost?->user_id,
|
'last_post_user_id' => $lastPost?->user_id,
|
||||||
@@ -100,13 +100,13 @@ class PortalController extends Controller
|
|||||||
'body' => $thread->body,
|
'body' => $thread->body,
|
||||||
'forum' => "/api/forums/{$thread->forum_id}",
|
'forum' => "/api/forums/{$thread->forum_id}",
|
||||||
'user_id' => $thread->user_id,
|
'user_id' => $thread->user_id,
|
||||||
'posts_count' => $thread->posts_count ?? 0,
|
'posts_count' => ($thread->posts_count ?? 0) + 1,
|
||||||
'views_count' => $thread->views_count ?? 0,
|
'views_count' => $thread->views_count ?? 0,
|
||||||
'user_name' => $thread->user?->name,
|
'user_name' => $thread->user?->name,
|
||||||
'user_avatar_url' => $thread->user?->avatar_path
|
'user_avatar_url' => $thread->user?->avatar_path
|
||||||
? Storage::url($thread->user->avatar_path)
|
? Storage::url($thread->user->avatar_path)
|
||||||
: null,
|
: null,
|
||||||
'user_posts_count' => $thread->user?->posts_count,
|
'user_posts_count' => ($thread->user?->posts_count ?? 0) + ($thread->user?->threads_count ?? 0),
|
||||||
'user_created_at' => $thread->user?->created_at?->toIso8601String(),
|
'user_created_at' => $thread->user?->created_at?->toIso8601String(),
|
||||||
'user_rank_name' => $thread->user?->rank?->name,
|
'user_rank_name' => $thread->user?->rank?->name,
|
||||||
'user_rank_badge_type' => $thread->user?->rank?->badge_type,
|
'user_rank_badge_type' => $thread->user?->rank?->badge_type,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class PostController extends Controller
|
|||||||
{
|
{
|
||||||
$query = Post::query()->withoutTrashed()->with([
|
$query = Post::query()->withoutTrashed()->with([
|
||||||
'user' => fn ($query) => $query
|
'user' => fn ($query) => $query
|
||||||
->withCount(['posts', 'thanksGiven', 'thanksReceived'])
|
->withCount(['posts', 'threads', 'thanksGiven', 'thanksReceived'])
|
||||||
->with(['rank', 'roles']),
|
->with(['rank', 'roles']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ class PostController extends Controller
|
|||||||
|
|
||||||
$post->loadMissing([
|
$post->loadMissing([
|
||||||
'user' => fn ($query) => $query
|
'user' => fn ($query) => $query
|
||||||
->withCount(['posts', 'thanksGiven', 'thanksReceived'])
|
->withCount(['posts', 'threads', 'thanksGiven', 'thanksReceived'])
|
||||||
->with(['rank', 'roles']),
|
->with(['rank', 'roles']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ class PostController extends Controller
|
|||||||
'user_avatar_url' => $post->user?->avatar_path
|
'user_avatar_url' => $post->user?->avatar_path
|
||||||
? Storage::url($post->user->avatar_path)
|
? Storage::url($post->user->avatar_path)
|
||||||
: null,
|
: null,
|
||||||
'user_posts_count' => $post->user?->posts_count,
|
'user_posts_count' => ($post->user?->posts_count ?? 0) + ($post->user?->threads_count ?? 0),
|
||||||
'user_created_at' => $post->user?->created_at?->toIso8601String(),
|
'user_created_at' => $post->user?->created_at?->toIso8601String(),
|
||||||
'user_location' => $post->user?->location,
|
'user_location' => $post->user?->location,
|
||||||
'user_thanks_given_count' => $post->user?->thanks_given_count ?? 0,
|
'user_thanks_given_count' => $post->user?->thanks_given_count ?? 0,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class ThreadController extends Controller
|
|||||||
->withMax('posts', 'created_at')
|
->withMax('posts', 'created_at')
|
||||||
->with([
|
->with([
|
||||||
'user' => fn ($query) => $query
|
'user' => fn ($query) => $query
|
||||||
->withCount(['posts', 'thanksGiven', 'thanksReceived'])
|
->withCount(['posts', 'threads', 'thanksGiven', 'thanksReceived'])
|
||||||
->with(['rank', 'roles']),
|
->with(['rank', 'roles']),
|
||||||
'latestPost.user.rank',
|
'latestPost.user.rank',
|
||||||
'latestPost.user.roles',
|
'latestPost.user.roles',
|
||||||
@@ -47,7 +47,7 @@ class ThreadController extends Controller
|
|||||||
$thread->refresh();
|
$thread->refresh();
|
||||||
$thread->loadMissing([
|
$thread->loadMissing([
|
||||||
'user' => fn ($query) => $query
|
'user' => fn ($query) => $query
|
||||||
->withCount(['posts', 'thanksGiven', 'thanksReceived'])
|
->withCount(['posts', 'threads', 'thanksGiven', 'thanksReceived'])
|
||||||
->with(['rank', 'roles']),
|
->with(['rank', 'roles']),
|
||||||
'latestPost.user.rank',
|
'latestPost.user.rank',
|
||||||
'latestPost.user.roles',
|
'latestPost.user.roles',
|
||||||
@@ -79,7 +79,7 @@ class ThreadController extends Controller
|
|||||||
|
|
||||||
$thread->loadMissing([
|
$thread->loadMissing([
|
||||||
'user' => fn ($query) => $query
|
'user' => fn ($query) => $query
|
||||||
->withCount(['posts', 'thanksGiven', 'thanksReceived'])
|
->withCount(['posts', 'threads', 'thanksGiven', 'thanksReceived'])
|
||||||
->with(['rank', 'roles']),
|
->with(['rank', 'roles']),
|
||||||
'latestPost.user.rank',
|
'latestPost.user.rank',
|
||||||
'latestPost.user.roles',
|
'latestPost.user.roles',
|
||||||
@@ -122,13 +122,13 @@ class ThreadController extends Controller
|
|||||||
'body' => $thread->body,
|
'body' => $thread->body,
|
||||||
'forum' => "/api/forums/{$thread->forum_id}",
|
'forum' => "/api/forums/{$thread->forum_id}",
|
||||||
'user_id' => $thread->user_id,
|
'user_id' => $thread->user_id,
|
||||||
'posts_count' => $thread->posts_count ?? 0,
|
'posts_count' => ($thread->posts_count ?? 0) + 1,
|
||||||
'views_count' => $thread->views_count ?? 0,
|
'views_count' => $thread->views_count ?? 0,
|
||||||
'user_name' => $thread->user?->name,
|
'user_name' => $thread->user?->name,
|
||||||
'user_avatar_url' => $thread->user?->avatar_path
|
'user_avatar_url' => $thread->user?->avatar_path
|
||||||
? Storage::url($thread->user->avatar_path)
|
? Storage::url($thread->user->avatar_path)
|
||||||
: null,
|
: null,
|
||||||
'user_posts_count' => $thread->user?->posts_count,
|
'user_posts_count' => ($thread->user?->posts_count ?? 0) + ($thread->user?->threads_count ?? 0),
|
||||||
'user_created_at' => $thread->user?->created_at?->toIso8601String(),
|
'user_created_at' => $thread->user?->created_at?->toIso8601String(),
|
||||||
'user_location' => $thread->user?->location,
|
'user_location' => $thread->user?->location,
|
||||||
'user_thanks_given_count' => $thread->user?->thanks_given_count ?? 0,
|
'user_thanks_given_count' => $thread->user?->thanks_given_count ?? 0,
|
||||||
|
|||||||
@@ -107,6 +107,11 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
return $this->hasMany(Post::class);
|
return $this->hasMany(Post::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function threads(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Thread::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function thanksGiven(): HasMany
|
public function thanksGiven(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(PostThank::class);
|
return $this->hasMany(PostThank::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user