修复产品分类分页

This commit is contained in:
Edward Yang 2022-11-04 14:06:54 +08:00
parent d8abb038b0
commit 1768a7fb77
3 changed files with 9 additions and 4 deletions

View File

@ -48,7 +48,7 @@ class ProductRepo
public static function getProductsByCategory($categoryId): AnonymousResourceCollection
{
$builder = self::getBuilder(['category_id' => $categoryId, 'active' => 1]);
$products = $builder->with('inCurrentWishlist')->get();
$products = $builder->with('inCurrentWishlist')->paginate();
return ProductSimple::collection($products);
}
@ -230,6 +230,7 @@ class ProductRepo
->get();
return $products;
}
public static function DeleteByIds($ids)
{
Product::query()->whereIn('id', $ids)->delete();

View File

@ -20,7 +20,8 @@ class CategoryController extends Controller
$data = [
'category' => $category,
'products' => $products->jsonSerialize(),
'products_format' => $products->jsonSerialize(),
'products' => $products,
];
return view('category', $data);

View File

@ -7,14 +7,17 @@
<x-shop-breadcrumb type="category" :value="$category" />
<div class="row">
@if (count($products))
@foreach ($products as $product)
@if (count($products_format))
@foreach ($products_format as $product)
<div class="col-6 col-md-3">@include('shared.product')</div>
@endforeach
@else
<x-shop-no-data />
@endif
</div>
{{ $products->links('shared/pagination/bootstrap-4') }}
</div>
@endsection