Laravel分页如何附加长字符串

Laravel分页如何附加长字符串,laravel,pagination,Laravel,Pagination,我刚开始学拉威尔。出现了一个问题,我从5000条分页记录的数据库中进行了选择 我的数据是这样的 380673113513 380673113514 380673113515 380673113516 ... 还有几千个 我把它们分成一个数组 $numberList = explode("\r\n", $request['inputList']); 我用分页方式进行选择 $objects = Number::has('object')->with('object')->whereI

我刚开始学拉威尔。出现了一个问题,我从5000条分页记录的数据库中进行了选择

我的数据是这样的 380673113513 380673113514 380673113515 380673113516 ... 还有几千个

我把它们分成一个数组

$numberList = explode("\r\n", $request['inputList']);
我用分页方式进行选择

$objects = Number::has('object')->with('object')->whereIn('number', $numberList)->Paginate(1000);
为了进行分页,我重新传输表单中的数据

{{ $objects->appends(['inputList' => $_REQUEST['inputList']])->links() }}
因此,我有这样的链接

如果有大量数据,则字符串很长,服务器返回错误414请求URI太大。我想我一开始做错了什么。如何在分页中正确传递如此大的请求


ps对不起,我用的是谷歌翻译)

你用的是POST方法吗?如果不是,您应该这样做,因为get请求的长度在发布到服务器配置的位置受到限制。

web.php:

Route::post('/'data, '<controllername>@<functionname>');
Route::post(“/”数据“@”);
控制器:

public function <functionname>(){
    //logic to create data
    $data = response()->json([
        'data' => $data
    ])
    return View::make('<view_name>', array('data' => $data));
}
公共功能(){
//创建数据的逻辑
$data=response()->json([
“数据”=>$data
])
返回视图::make(“”,数组('data'=>$data));
}
然后,您应该能够在视图中访问它:

{{$data[0]-><attribute>}}
{{$data[0]->}
或者做一个foreach语句…

web.php

    Route::get('/test', [
    'uses' => 'TestController@test',
    'as'=> 'test'
]);

Route::post('/test', [
    'uses' => 'TestController@test',
    'as'=> 'test'
]);
控制器

public function test(Request $request)
{
        $numberList = explode("\r\n", $request['inputList']);
        $objects = Number::has('object')->with('object')->whereIn('number', $numberList)->Paginate(10);
        return view('objects.test')->with('objects', $objects);
}
看法


去
@如果($objects->count()>0)
@foreach($objects作为$object)
{{$object->number}
{{$object->object->fio}
@endforeach
{{$objects->links()}
@恩迪夫
当我在表单中提出请求时,结果将正常显示。 但当我尝试转到第2页时,我得到了一个包含表单的空白页。 这都是因为当您转到第2页时,$request['inputList']已经为空,因此,$objects也为空。
这是为什么?

我使用post从textarea获取数据。但据我所知,要进行分页,我需要将它们重新传输到URL,我认为您可以查看数据。像return Route::post(“/”data“@”)一样,我在当前的应用程序中使用几千条记录进行了类似的操作,没有任何问题。但是如果这里有任何帮助,如何对该数据集进行分页。为什么要在url中传输数据?我真的不明白你想做什么,但对于分页,你只需要页面参数
<form class="form-horizontal" action="{{ route('test') }}" method="POST">
   <textarea class="form-control" name="inputList" id="inputList"></textarea>
   <button type="submit" class="btn btn-default">go</button>
   <input type="text" name="_token" value="{{ csrf_token() }}" hidden>
</form>

        @if ($objects->count() > 0)
            @foreach( $objects as $object)
                <tr>
                    <td>{{ $object->number }}</td>
                    <td>{{ $object->object->fio }}</td>
                </tr>
            @endforeach
            {{ $objects->links() }}
        @endif