【发布时间】:2023-03-05 02:31:01
【问题描述】:
我一直在寻找类似上述问题的问题,但我找不到,所以我会做一个
我的问题是,当我用 Laravel Livewire 做一个非常简单的分页时,第一页看起来很好,但是当我点击“下一页/页码”时,结果就消失了,即使还有更多的结果秀,我完全不知道,无论我如何尝试。
这是我的组件代码:
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Http\Request;
use DB;
use Livewire\WithPagination;
class Category extends Component
{
use WithPagination;
public function render(Request $request)
{
$id = $request->id;
$product_count = DB::table('product')->where('category_id', $id)->count();
$page = $request->page ?? 1;
$product_all = DB::table('product')->where('category_id', $id)->paginate(3);
return view('livewire.category',[
'product_all' => $product_all,
'product_count' => $product_count,
'page' => $page,
]);
}
}
这是我的查看代码:
<div class="row">
@foreach ($product_all as $product)
<div class="col-lg-4 col-md-6 col-12 mt-4 pt-2">
@php
product($product);
@endphp
</div>
@endforeach
<!-- PAGINATION START -->
@if ($product_all instanceof \Illuminate\Pagination\LengthAwarePaginator)
{{ $product_all->links() }}
@endif
<!-- PAGINATION END -->
</div>
还有一个小提示,我尝试在没有 livewire 的情况下进行分页(只是正常的 laravel 分页),它工作得非常好,这就是为什么我真的对正在发生的事情一无所知
我已经包含了 livewire @livewireStyles 和 @livewireScripts,我在其他任何地方都找不到答案,因为我没有看到任何与我的问题相匹配的问题,而且我对 livewire 有点陌生
【问题讨论】: