Laravel 分页到特定部分

Laravel Pagination To Certain Section

伙计们 我使用 Laravel 的默认分页和 bootstrap 作为其样式框架。 我想在点击分页link后将我的页面定向到某个html部分,目前我只知道如何分页如下代码:

控制器:

$data = Products::paginate(9);
return view('index', ['data' => $data]);

Blade:

{{ $data->links() }}

所以,每次单击分页 link 按钮时,我都想将我的页面定向到 html 中的某个部分。我怎样才能做到这一点?

很抱歉我的解释不力,如果您需要更多详细信息,请联系我。

谢谢

您应该制作一个 blade 文件,如下所示: pagination.blade.php

@if ($paginator->hasPages())
<ul class="pagination justify-content-center">
    @if ($paginator->onFirstPage())
        <li class="paginate_button page-item previous disabled">
            <a href="javascript:void(0)" class="page-link disabled">قبلی</a>
        </li>
    @else
        <li class="paginate_button page-item previous">
            <a href="javascript:void(0)" class="page-link" data-page="{{ $paginator->currentPage()-1 }}">pre</a>
        </li>
    @endif
    @foreach ($elements as $element)
        @if (is_string($element))
            <li class="paginate_button page-item active">
                <a href="javascript:void(0)" class="page-link" >{{ $element }}</a>
            </li>
        @endif
        @if (is_array($element))
            @foreach ($element as $page => $url)
                @if ($page == $paginator->currentPage())
                    <li class="paginate_button page-item active"><a href="javascript:void(0)" class="page-link">{{ $page }}</a></li>
                @else
                    <li class="paginate_button page-item "><a href="javascript:void(0)" class="page-link" data-page="{{ $page }}">{{ $page }}</a></li>
                @endif
            @endforeach
        @endif
    @endforeach
    {{-- next page  --}}
    @if ($paginator->hasMorePages())
        <li class="paginate_button page-item next ">
            <a href="javascript:void(0)" class="page-link" data-page="{{ $paginator->currentPage()+1 }}">next</a>
        </li> 
    @else
        <li class="paginate_button page-item next disabled">
            <a href="javascript:void(0)" class="disabled">بعدی</a>
        </li>
    @endif
</ul>
@endif

然后像这样创建一个 blade 文件: table.blade.php

  @if(isset($permissions))
@php
    $paginator=$permissions;
@endphp
<table class="table table-striped">
    <thead>
        <tr>
            heaers tags
        </tr>
    </thead>
    <tbody id="table-data">
        
        @foreach ($permissions as $permission)
            tr tags
        @endforeach
    </tbody>
</table>
@endif

<div class="col-md-12">
    {{ $paginator->links('sections.pagination') }}
</div>

然后在控制器方法中:

public function index(Request $request)
{
    $permissions=Permission::paginate(5);
    if($request->ajax()){
        return view('sections.table',compact('permissions'));
    }
    return view('permission.index',compact('permissions'));
}