MyLibrary's avatar

Pagination with existing paramethers in the URL?

I know my threads subjects may confuse some of you, but let me explain a bit better:

I've the resourceful route:

Route::resource('deposits', 'DepositsController');

So in order to show all deposits I ofcurse visit the URI: url.com/deposits

And at the bottom I've the pagination feature (using "render"), that redirect to the deisred page, for instance:

url.com/deposits?page=2

So far, all good, now lets take it a bit further, I've built a sorting feature that look for attributes in the URI and sorting the results accordingly, so for example:

url.com/deposits?employee=1&flag=&deposit_type=&documents=&client_name=&phone=&comment=&id=&amount_from=&amount_to=&datePicker=&amount=&creation_date=

Will display records according to the attributes, so far, again, it's all good!

The problem starts when the there are more than 10 records (which I've defined this amount earlier) it still redirect to:

url.com/deposits?page=2

Instead of

url.com/deposits?employee=1&flag=&deposit_type=&documents=&client_name=&phone=&comment=&id=&amount_from=&amount_to=&datePicker=&amount=&creation_date=&page=2

And this is how the deposits sorting is written:

$deposits = Deposit::filterBy(
            [
                'id'             => urlParamOrNull('id'),
                'employee_id'    => urlParamOrNull('employee'),
                'type_id'        => urlParamOrNull('deposit_type'),
                'amount'         => urlParamOrNull('amount'),
                'amountOperator' => urlParamOrNull('amount_operator'),
                'flag_id'        => urlParamOrNull('flag'),
                'comment'        => urlParamOrNull('comment'),
                'client_name'    => urlParamOrNull('client_name'),
                'phone'          => urlParamOrNull('phone'),
                'documents'      => urlParamOrNull('documents'),
                'created_at'     => urlParamOrNull('creation_date'),
            ])
                           ->orderBy('created_at', 'desc')
                           ->paginate($this->recordsPerPage);

Can you please try to help me our? how can I define that the paginate will add the page attribute to the end of the URI and won't change it completely to the actual route path + the page number?

Thanks once again!

0 likes
4 replies
MyLibrary's avatar

links() method is not supported in Laravel 5.0.

MattCroft's avatar

ah in that case i believe you can do the same but with render instead in 5.0.

MyLibrary's avatar

Perfect Matt! I appreciate your kind help! (should have read it by my self, somehow missed that section =} )

Thanks for your kind help!

Please or to participate in this conversation.