ackuang's avatar

Persists checkbox value through pagination (Laravel 4)

http://stackoverflow.com/questions/17929060/how-to-persist-checked-items-across-pagination-requests-in-laravel

I try to implement using answer in the link above but seems not working. I am unable to keep the checkbox values with pagination. There is a form after collecting all checkbox, then only post the form together with checkbox. My code as follows:

View:

{{ Form::open(array('url' => ('postToAnotherForm'), 'class'=>'form-horizontal')) }}
    <div class="table-responsive">
        <table class="table table-bordered table-striped">
            <tr>
                <th>Checkbox</th>
            </tr>
            @foreach($items as $item)
            <tr>
                <td>{{ Form::checkbox('abc[]', $item->id) }}</td>
            </tr>
            @endforeach
        </table>
    </div>
    <div class="paginate">
        {{ $items->appends(Input::except('page'))->links() }}
    </div>
    {{ Form::submit('Next', array('class'=>'btn btn-primary pull-right')) }}
{{ Form::close() }}

Controller:

$items= Item::paginate(2);      
$checked_items = [];
    if (Session::has('checked_items'))
        $checked_items = Session::get('checked_items');

    $checked_items = array_merge($checked_items, Input::get('abc'));
    Session::flash('checked_items', $checked_items);

    return View::make('form', compact('items'))->withInput($checked_items);

Anyone has any idea? Thanks for giving some idea.

0 likes
1 reply
ackuang's avatar

Anyone can guide me? Many many thanks.

Please or to participate in this conversation.