Laravel 4分页 - 无法通过第1页

时间:2014-04-22 09:43:48

标签: laravel pagination eloquent

我创建了一些搜索功能,用户可以在其中选择类型,池,日期和时间。我似乎无法让分页器工作,因为当我点击第2页时,结果就会消失。

我试图附加$ query-> links()函数,但我的尝试都没有成功。

网址如下所示:http://localhost:8080/nih/public/bassengweb/data?time_maling=1&pool_id=1&fraDato=14%2F04%2F2014&tilDato=22%2F04%2F2014&fraTid=00%3A01&tilTid=23%3A59

视图文件的代码:

@extends('default')

@section('content')

    <h1>ADMIN SØK</h1>

    {{ Form::open(array('url' => 'bassengweb/data', 'method' => 'GET')) }}
    <table>
        <tr>
            <td>{{ Form::label('time_maling', 'Timemåling') }}</td>
            <td>{{ Form::checkbox('time_maling', 1) }}</td>
            <td>{{ Form::label('3_time_maling', '3. Timemåling') }}</td>
            <td>{{ Form::checkbox('3_time_maling', 1) }}</td>
            <td>{{ Form::label('oppgaver', 'Oppgaver') }}</td>
            <td>{{ Form::checkbox('oppgaver', 1) }}</td>
            <td>{{ Form::label('pool_id', 'Basseng') }}</td>
            <td>{{ Form::select('pool_id', $pools, Input::old('pool_id')) }}</td>
        </tr>
        <tr>
            <td>{{ Form::label('dagsoppg', 'Dagvakt') }}</td>
            <td>{{ Form::checkbox('dagsoppg', 1) }}</td>
            <td>{{ Form::label('kveldsoppg', 'Kveldsvakt') }}</td>
            <td>{{ Form::checkbox('kveldsoppg', 1) }}</td>
            <td>{{ Form::label('helgoppg', 'Helgevakt') }}</td>
            <td>{{ Form::checkbox('helgsoppg', 1) }}</td>
        </tr>
        <tr>
            <td>{{ Form::label('kontcm', 'Kontroll CM') }}</td>
            <td>{{ Form::checkbox('kontcm', 1) }}</td>
            <td>{{ Form::label('arduino', 'Arduino') }}</td>
            <td>{{ Form::checkbox('arduino', 1) }}</td>
            <td><hr/></td>
        </tr>
        <tr>
            <td>{{ Form::label('fraDato', 'Fra dato: ') }}</td>
            <td>{{ Form::text('fraDato', Input::old('fraDato'), array('placeholder' => $date)) }}</td>
            <td>{{ Form::label('tilDato', 'Til dato: ') }}</td>
            <td>{{ Form::text('tilDato', Input::old('tilDato'), array('placeholder' => $date)) }}</td>
        </tr>
        <tr>
            <td>{{ Form::label('fraTid', 'Fra klokka: ') }}</td>
            <td>{{ Form::text('fraTid', Input::old('fraTid'), array('placeholder' => '10:55:31')) }}</td>
            <td>{{ Form::label('tilTid', 'Til klokka: ') }}</td>
            <td>{{ Form::text('tilTid', Input::old('tilTid'), array('placeholder' => '10:55:31')) }}</td>
            <td>{{ Form::submit('Søk') }}<td>
        </tr>
    </table>
    {{ Form::close() }}

    @if(isset($data))
        <table  class='table table-hover'>
            <tr>
                <td>ID</td>
                <td>Tittel</td>
                <td>Verdi</td>
                <td>Ansatt ID</td>
                <td>Dato</td>
                <td>Tid</td>
        @if($type === 'measurement')
                <td>Basseng</td>
            </tr>
            @foreach($data as $dataItem)
                <tr>
                    <td>{{ $dataItem->id }}</td>
                    <td>{{ $dataItem->measurements[0]->title }}</td>
                    <td>{{ $dataItem->value }}</td>
                    <td>{{ $dataItem->emps->user_name }}</td>
                    <td>{{ date('d/m/Y', strtotime($dataItem->date)) }}</td>
                    <td>{{ $dataItem->time }}</td>
                    @foreach($dataItem->measurements as $measurement)
                        <td>{{ $pools[$measurement->pivot->pool_id] }}</td>
                    @endforeach
                    <td>{{ HTML::linkRoute('edit_data', 'Rediger', $dataItem->id) }}</td>
                    <td>{{ HTML::linkRoute('delete_confirm', 'Slett', $dataItem->id) }}
                    </td>
                </tr>
            @endforeach
                    </table>
            {{ $data->appends(array($type => 1, Input::except('page')))->links() }}
        @elseif($type === 'task')
            </tr>
            @foreach($data as $dataItem)
                <tr>
                    <td>{{ $dataItem->id }}</td>
                    <td>{{ $dataItem->tasks[0]->title }}</td>
                    <td>{{ $dataItem->value }}</td>
                    <td>{{ $dataItem->emps->user_name }}</td>
                    <td>{{ date('d/m/Y', strtotime($dataItem->date)) }}</td>
                    <td>{{ $dataItem->time }}</td>
                    <td>{{ HTML::linkRoute('edit_data', 'Rediger', $dataItem->id) }}</td>
                    <td>{{ HTML::linkRoute('delete_confirm', 'Slett', $dataItem->id) }}</td>
                </tr>
            @endforeach
        @endif


    @endif
@stop

感谢。

1 个答案:

答案 0 :(得分:1)

您在追加方法中嵌套数组:

$data->appends(array($type => 1, Input::except('page')))->links()
// returns
array(
  $type => 1,
  array(
    ... // Input/Request params are ignored as a nested array
  )
)

将其更改为:

$data->appends(array_merge(array($type => 1), Input::except('page')))->links()