Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Http/Controllers/Blade/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function show(Request $request): View
abort(404);
}

$post->load(['parent', 'parent.author', 'parent.thread', 'parent.thread.category']);

if ($request->user() !== null) {
UserViewingPost::dispatch($request->user(), $post);
}
Expand All @@ -45,6 +47,10 @@ public function create(Request $request): View

$post = $request->has('post_id') ? $thread->posts->find($request->input('post_id')) : null;

if ($post !== null) {
$post->load(['author', 'thread']);
}

return ViewFactory::make('forum::post.create', compact('thread', 'post'));
}

Expand All @@ -70,11 +76,12 @@ public function edit(Request $request): View
}

$this->authorize('edit', $post);

UserEditingPost::dispatch($request->user(), $post);


$thread = $post->thread;
$category = $post->thread->category;
$post->load(['parent', 'parent.author', 'parent.thread', 'parent.thread.category']);

UserEditingPost::dispatch($request->user(), $post);

return ViewFactory::make('forum::post.edit', compact('category', 'thread', 'post'));
}
Expand All @@ -96,6 +103,7 @@ public function confirmDelete(Request $request): View
{
$thread = $request->route('thread');
$post = $request->route('post');
$post->load(['parent', 'parent.author', 'parent.thread', 'parent.thread.category']);

return ViewFactory::make('forum::post.confirm-delete', ['category' => $thread->category, 'thread' => $thread, 'post' => $post]);
}
Expand All @@ -104,6 +112,7 @@ public function confirmRestore(Request $request): View
{
$thread = $request->route('thread');
$post = $request->route('post');
$post->load(['parent', 'parent.author', 'parent.thread', 'parent.thread.category']);

return ViewFactory::make('forum::post.confirm-restore', ['category' => $thread->category, 'thread' => $thread, 'post' => $post]);
}
Expand Down Expand Up @@ -140,7 +149,7 @@ public function pendingApproval(Request $request): View
->notFirstInThread()
->pendingApproval()
->orderBy('created_at', 'desc')
->with('thread', 'author');
->with('thread', 'thread.category', 'author', 'parent', 'parent.thread', 'parent.thread.category');

// Get accessible category IDs for the current user
$accessibleCategoryIds = CategoryAccess::getFilteredIdsFor($request->user());
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Blade/ThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function show(Request $request): View
}

$posts = $postsQuery
->with('author', 'thread')
->with('author', 'thread', 'parent', 'parent.author', 'parent.thread', 'parent.thread.category')
->orderBy('created_at', 'asc')
->paginate();

Expand Down Expand Up @@ -303,7 +303,7 @@ public function pendingApproval(Request $request): View
$threads = Thread::notDeleted()
->pendingApproval()
->orderBy('created_at', 'desc')
->with('category', 'author', 'lastPost', 'lastPost.author', 'lastPost.thread');
->with('category', 'firstPost', 'author', 'lastPost', 'lastPost.author', 'lastPost.thread');

// Get accessible category IDs for the current user
$accessibleCategoryIds = CategoryAccess::getFilteredIdsFor($request->user());
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Livewire/Pages/PostShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PostShow extends Component
{
public function render(Request $request): View
{
$post = $request->route('post');
$post = $request->route('post')->load('thread.category', 'parent', 'parent.author', 'parent.thread.category');

if (!$post->isAccessibleTo($request->user())) {
abort(404);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Livewire/Pages/PostsPendingApproval.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function getPosts(Request $request): Collection
->notFirstInThread()
->pendingApproval()
->orderBy('created_at', 'desc')
->with('thread', 'author');
->with('thread.category', 'author', 'parent', 'parent.author', 'parent.thread.category');

$accessibleCategoryIds = CategoryAccess::getFilteredIdsFor($request->user());

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Livewire/Pages/ThreadReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class ThreadReply extends Component

public function mount(Request $request)
{
$this->thread = $request->route('thread');
$this->thread = $request->route('thread')->load('category');

if (!$this->thread->category->isAccessibleTo($request->user())) {
abort(404);
}

if ($request->input('parent_id')) {
$this->parent = $this->thread->posts->find($request->input('parent_id'));
$this->parent = $this->thread->posts()->find($request->input('parent_id'));
}

UserCreatingPost::dispatch($request->user(), $this->thread);
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Livewire/Pages/ThreadShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ThreadShow extends EventfulPaginatedComponent

public function mount(Request $request)
{
$this->thread = $request->route('thread');
$this->thread = $request->route('thread')->load('category');

if (!$this->thread->isAccessibleTo($request->user())) {
abort(404);
Expand Down Expand Up @@ -243,7 +243,7 @@ public function render(Request $request): View
}

$posts = $postsQuery
->with('author', 'thread')
->with('author', 'thread.category', 'parent', 'parent.author', 'parent.thread.category')
->orderBy('created_at', 'asc')
->paginate();

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function scopeRecent(Builder $query): Builder

public function scopeWithPostAndAuthorRelationships(Builder $query): Builder
{
return $query->with('firstPost', 'lastPost', 'firstPost.author', 'lastPost.author', 'lastPost.thread', 'author');
return $query->with('category', 'firstPost', 'lastPost', 'firstPost.author', 'lastPost.author', 'lastPost.thread', 'author');
}

public function scopeOrdered(Builder $query): Builder
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Access/CategoryAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class CategoryAccess
{
const DEFAULT_SELECT = ['*'];
const DEFAULT_WITH = ['newestThread', 'latestActiveThread', 'newestThread.lastPost', 'latestActiveThread.lastPost'];
const DEFAULT_WITH = ['newestThread', 'latestActiveThread', 'newestThread.lastPost.thread', 'latestActiveThread.lastPost.thread'];

public static function getPrivateAncestor(?User $user, Category $category): ?Category
{
Expand Down