current state
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\ContentType;
|
||||
use App\Models\Artwork;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
@@ -16,6 +17,7 @@ class CategoryPageController extends Controller
|
||||
abort(404);
|
||||
}
|
||||
|
||||
|
||||
if ($categoryPath === null || $categoryPath === '') {
|
||||
// No category path: show content-type landing page (e.g., /wallpapers)
|
||||
$rootCategories = $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get();
|
||||
@@ -41,6 +43,7 @@ class CategoryPageController extends Controller
|
||||
->where('slug', strtolower(array_shift($segments)))
|
||||
->first();
|
||||
|
||||
|
||||
if (! $current) {
|
||||
abort(404);
|
||||
}
|
||||
@@ -56,12 +59,28 @@ class CategoryPageController extends Controller
|
||||
$subcategories = $category->children()->orderBy('sort_order')->orderBy('name')->get();
|
||||
$rootCategories = $contentType->rootCategories()->orderBy('sort_order')->orderBy('name')->get();
|
||||
|
||||
// Placeholder artworks paginator (until artwork data is wired).
|
||||
$page = max(1, (int) $request->query('page', 1));
|
||||
$artworks = new LengthAwarePaginator([], 0, 40, $page, [
|
||||
'path' => $request->url(),
|
||||
'query' => $request->query(),
|
||||
]);
|
||||
// Collect category ids for the category + all descendants recursively
|
||||
$collected = [];
|
||||
$gather = function (Category $cat) use (&$gather, &$collected) {
|
||||
$collected[] = $cat->id;
|
||||
foreach ($cat->children as $child) {
|
||||
$gather($child);
|
||||
}
|
||||
};
|
||||
// Ensure children relation is loaded to avoid N+1 recursion
|
||||
$category->load('children');
|
||||
$gather($category);
|
||||
|
||||
// Load artworks that are attached to any of these categories
|
||||
$query = Artwork::whereHas('categories', function ($q) use ($collected) {
|
||||
$q->whereIn('categories.id', $collected);
|
||||
})->published()->public();
|
||||
|
||||
// Paginate results
|
||||
$perPage = 40;
|
||||
$artworks = $query->orderBy('published_at', 'desc')
|
||||
->paginate($perPage)
|
||||
->withQueryString();
|
||||
|
||||
$page_title = $category->name;
|
||||
$page_meta_description = $category->description ?? ($contentType->name . ' artworks on Skinbase');
|
||||
|
||||
Reference in New Issue
Block a user