我正在尝试查看检索类别中的所有产品并将它们分页到页面中。
我能够获取任何类别中的所有产品,并且工作正常,但是当我尝试对它们进行分页时,它会抛出此错误:
方法 Illuminate\Database\Eloquent\Collection::links 不存在。(查看:C:\xampp\htdocs\E-Commerce\resources\views\pages\products.blade.php)。
这是我的代码。
public function show(Category $category, Request $request)
{
$categories = Category::where('id', $request->category->id)->paginate(12);
return view('pages.products')->with([
'categories' => $categories,
]);
这是我的观点。
@extends('layouts/default')
@section('title', '| Products')
@section('content')
@forelse ($categories as $category)
<h1 class="text-center">{{ $category->name }}</h1>
<div class="row mt-5 m-5">
@foreach ($category->products as $product)
<div class="cols m-4 shadow-lg product product-box">
<a href="">
<h4 class="text-center">{{ $product->name }}</h4>
<img class="m-auto" src="{{ asset('images/welcome2.jpg') }}" width="150px">
<br>
<small class="text-center">{{ $product->details }}</small>
<br>
<h6 class="float-right mr-1">$ {{ $product->price }}</h6>
</a>
</div>
@endforeach
{{ $category->products->links() }}
</div>
@empty
<h1>There are no categories yet!</h1>
@endforelse
@endsection
达令说
慕的地6264312