Current state
This commit is contained in:
34
app/Http/Controllers/BrowseCategoriesController.php
Normal file
34
app/Http/Controllers/BrowseCategoriesController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BrowseCategoriesController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Use Eloquent models for canonical category URLs and grouping
|
||||
$contentTypes = \App\Models\ContentType::with(['rootCategories.children'])->orderBy('id')->get();
|
||||
|
||||
// Prepare categories grouped by content type and a flat list of root categories
|
||||
$categoriesByType = [];
|
||||
$categories = collect();
|
||||
foreach ($contentTypes as $ct) {
|
||||
$rootCats = $ct->rootCategories;
|
||||
foreach ($rootCats as $cat) {
|
||||
// Attach subcategories
|
||||
$cat->subcategories = $cat->children;
|
||||
$categories->push($cat);
|
||||
}
|
||||
$categoriesByType[$ct->slug] = $rootCats;
|
||||
}
|
||||
|
||||
return view('browse-categories', [
|
||||
'contentTypes' => $contentTypes,
|
||||
'categoriesByType' => $categoriesByType,
|
||||
'categories' => $categories,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user