This commit is contained in:
parent
e1430873a1
commit
43c7a5461e
|
|
@ -31,6 +31,11 @@ class Category extends Base
|
|||
return $this->hasMany(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function activeChildren(): HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_id')->where('active', true);
|
||||
}
|
||||
|
||||
public function descriptions(): HasMany
|
||||
{
|
||||
return $this->hasMany(CategoryDescription::class);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class CategoryRepo
|
|||
{
|
||||
$topCategories = Category::query()
|
||||
->from('categories as c')
|
||||
->with(['description', 'children.description'])
|
||||
->with(['description', 'activeChildren.description'])
|
||||
->where('parent_id', 0)
|
||||
->where('active', true)
|
||||
->orderBy('position')
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ class CategoryController extends Controller
|
|||
|
||||
public function show(Request $request, Category $category)
|
||||
{
|
||||
if (! $category->active) {
|
||||
return redirect(shop_route('home.index'));
|
||||
}
|
||||
$filterData = $request->only('attr', 'price', 'sort', 'order', 'per_page');
|
||||
$products = ProductRepo::getProductsByCategory($category->id, $filterData);
|
||||
$category->load('description');
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ class CategoryDetail extends JsonResource
|
|||
'url' => shop_route('categories.show', ['category' => $this]),
|
||||
];
|
||||
|
||||
if ($this->relationLoaded('children') && $this->children->count() > 0) {
|
||||
$item['children'] = self::collection($this->children);
|
||||
if ($this->relationLoaded('activeChildren') && $this->activeChildren->count() > 0) {
|
||||
$item['children'] = self::collection($this->activeChildren);
|
||||
} else {
|
||||
$item['children'] = [];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue