This commit is contained in:
2022-08-19 19:58:30 +08:00
parent 4a3a710385
commit f45af9c783
2 changed files with 43 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Article;
use App\Models\Category;
class CategoryController extends Controller
@@ -32,11 +33,26 @@ class CategoryController extends Controller
$pageCount = 100;
}
$articles = $category->relations(Category::TYPE_ARTICLE)
->where('status', 1)
->latest('sort')
->latest('created_at')
->paginate($pageCount);
if ($category->id == 37) {
$categories = Category::get();
$children = array_merge([$category->id], getAllChild($categories, $category->id));
$articles = Article::query()
->whereHas('categories', function ($q) use ($children) {
$q->whereIn('id', $children);
})
->where('status', 1)
->latest('sort')
->latest('created_at')
->paginate($pageCount);
} else {
$articles = $category->relations(Category::TYPE_ARTICLE)
->where('status', 1)
->latest('sort')
->latest('created_at')
->paginate($pageCount);
}
$parent = $category;
if (! $category->getChildrenCount() && $category->parent) {