Php laravel分页返回不同的页面

Php laravel分页返回不同的页面,php,laravel,pagination,Php,Laravel,Pagination,我正在从事一个laravel项目,在那里我从API获取数据,然后我想在页面上显示它。我希望回报被分散在4页,每页10个结果。到目前为止,我所拥有的,似乎应该是有效的,但我缺少了一点,所以任何建议和帮助都将不胜感激。这就是它如何处理代码: 1) 用户在搜索框中键入图书标题 <form method=POST action='/search'> @csrf <input type="text" name="search_term"/>

我正在从事一个laravel项目,在那里我从API获取数据,然后我想在页面上显示它。我希望回报被分散在4页,每页10个结果。到目前为止,我所拥有的,似乎应该是有效的,但我缺少了一点,所以任何建议和帮助都将不胜感激。这就是它如何处理代码:

1) 用户在搜索框中键入图书标题

<form method=POST action='/search'>
        @csrf
        <input type="text" name="search_term"/>
        <input type="submit" value="Search"/>
    </form>
3) 结果将显示在我的刀片上

@extends('home')
@section('content')
@foreach($books_to_show as $entries)
<div class="row">
    <div class="col-sm-auto">
        <img class="w-50 img-thumbnail" src={{$entries['volumeInfo']['imageLinks']['smallThumbnail']}}/>
    </div>
    <div class="col-sm">
        {{$entries['volumeInfo']['title']}}<br/>
        @if($entries['volumeInfo']['authors']!=null)
        by: 
        @foreach($entries['volumeInfo']['authors'] as $authors)
            {{$authors}}
        @endforeach
        @endif

    </div>
</div>

@endforeach
{{$books_to_show->links()}}
@endsection
@extends('home'))
@节(“内容”)
@foreach($books\u to\u显示为$entries)
{{$entries['volumeInfo']['title']}}
@如果($entries['volumeInfo']['authors']!=null) 作者: @foreach($authors形式的条目['volumeInfo']['authors'] {{$authors}} @endforeach @恩迪夫 @endforeach {{$books\u to\u show->links()} @端部
这一切都很好,正如预期的那样。我在视图中得到了10个结果,然后在底部有一个条,显示了4个不同的页面供我选择

当我第一次键入搜索词(如“威廉·莎士比亚”)时,我的页面url为:
localhost:8000/搜索

但是,当我点击任何页面时,我的url变成:
http://localhost:8000/?page=2

我理解,?页面=*是分页如何确定您正在查看的页面,并且应该发送回控制器。但是,我想我在把它发送回控制器时遗漏了一些东西


对此仍然有点新鲜,因此任何建议都非常感谢。

lengshawarepaginator
接受其构造函数中的第五个参数:选项数组

路径
选项
$books\u to\u show=new lengtashawarepaginator($current\u book\u page,count($book\u collection),10,$current\u page[
//这将修复分页链接的路径
'path'=>Lengshawarepaginator::resolveCurrentPath()
]);
顺便说一句,在一个完全不同的问题上,Laravel通过为您分割收藏让您的生活更轻松,请查看:

$current\u book\u page=$book\u collection->forPage($current\u page,10);
希望有帮助:)

@extends('home')
@section('content')
@foreach($books_to_show as $entries)
<div class="row">
    <div class="col-sm-auto">
        <img class="w-50 img-thumbnail" src={{$entries['volumeInfo']['imageLinks']['smallThumbnail']}}/>
    </div>
    <div class="col-sm">
        {{$entries['volumeInfo']['title']}}<br/>
        @if($entries['volumeInfo']['authors']!=null)
        by: 
        @foreach($entries['volumeInfo']['authors'] as $authors)
            {{$authors}}
        @endforeach
        @endif

    </div>
</div>

@endforeach
{{$books_to_show->links()}}
@endsection