mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-01-27 22:40:09 -06:00
update: separate forum categories into their own model
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Forum;
|
||||
use App\Models\ForumCategory;
|
||||
use App\Models\Post;
|
||||
use App\Models\Topic;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -29,17 +30,17 @@ class ForumController extends Controller
|
||||
public function index(Request $request): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
{
|
||||
return view('forum.index', [
|
||||
'categories' => Forum::query()
|
||||
'categories' => ForumCategory::query()
|
||||
->with([
|
||||
'forums' => fn ($query) => $query
|
||||
->whereRelation('permissions', [['read_topic', '=', 1], ['group_id', '=', $request->user()->group_id]]),
|
||||
->whereRelation('permissions', [['read_topic', '=', 1], ['group_id', '=', $request->user()->group_id]])
|
||||
->orderBy('position'),
|
||||
'forums.latestPoster' => fn ($query) => $query->withTrashed(),
|
||||
'forums.lastRepliedTopic',
|
||||
])
|
||||
->whereNull('parent_id')
|
||||
->whereRelation('permissions', [['read_topic', '=', 1], ['group_id', '=', $request->user()->group_id]])
|
||||
->orderBy('position')
|
||||
->get(),
|
||||
->get()
|
||||
->filter(fn ($category) => $category->forums->isNotEmpty()),
|
||||
'num_posts' => Post::count(),
|
||||
'num_forums' => Forum::count(),
|
||||
'num_topics' => Topic::count(),
|
||||
@@ -49,24 +50,13 @@ class ForumController extends Controller
|
||||
/**
|
||||
* Show Forums And Topics Inside.
|
||||
*/
|
||||
public function show(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Illuminate\Http\RedirectResponse
|
||||
public function show(Request $request, int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\Illuminate\Http\RedirectResponse
|
||||
{
|
||||
// Find the topic
|
||||
$forum = Forum::findOrFail($id);
|
||||
|
||||
// Check if this is a category or forum
|
||||
if ($forum->parent_id === null) {
|
||||
return to_route('forums.categories.show', ['id' => $forum->id]);
|
||||
}
|
||||
|
||||
// Check if the user has permission to view the forum
|
||||
if (!$forum->getPermission()?->read_topic) {
|
||||
return to_route('forums.index')
|
||||
->withErrors('You Do Not Have Access To This Forum!');
|
||||
}
|
||||
|
||||
return view('forum.forum_topic.index', [
|
||||
'forum' => $forum,
|
||||
'forum' => Forum::query()
|
||||
->with('category')
|
||||
->whereRelation('permissions', [['read_topic', '=', 1], ['group_id', '=', $request->user()->group_id]])
|
||||
->findOrFail($id),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user