Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbo's avatar
Level 3

Database: Pagination - Links() not working

good day,

I'm setting up a complex query. Depending on different variables. Coming from a form.

Loading of the page works fine. Also the setting of pagination -> links().

$request =

Request {#43 ▼
  #json: null
  #convertedFiles: []
  #userResolver: Closure {#446 ▶}
  #routeResolver: Closure {#440 ▶}
  +attributes: ParameterBag {#45 ▶}
  +request: ParameterBag {#44 ▼
    #parameters: array:17 [▼
      "_token" => "Ds5L96HxUVDNVRDbd413P5MRDfsMQnpKgethC7lK"
      "formatted_address" => ""
      "dp_street" => ""
      "dp_housenum" => ""
      "dp_zipcode" => ""
      "dp_place_name" => ""
      "dp_department_name" => "Zuid-Holland"
      "dp_country_name" => ""
      "dp_latitude" => "52.0207975"
      "dp_longitude" => "4.4937836"
      "type" => "dps"
      "dp_distance" => ""
      "dp_department_id" => "31"
      "dp_place_name_id" => ""
      "dp_region_name" => ""
      "dp_region_id" => ""
      "dp_place_id" => ""
    ]
  }

But when you click next the query breaks. It seems that the query is not executed because the variable out of the request are missing.

$request =

Request {#43 ▼
  #json: null
  #convertedFiles: []
  #userResolver: Closure {#445 ▶}
  #routeResolver: Closure {#439 ▶}
  +attributes: ParameterBag {#45 ▶}
  +request: ParameterBag {#51 ▼
    #parameters: array:1 [▼
      "page" => "2"
    ]
  }

It seems that links() needs the same #request variables. How can i pass these? I tried " appending" but did not work out.

{{ $dps->appends([$request->toarray()])->links() }}

It is an search form. So the variables differ every time.

Is there a way to solve this?

thanks in advance.

br

maarten

0 likes
4 replies
ftiersch's avatar
ftiersch
Best Answer
Level 28
{{ $dps->appends([$request->toarray()])->links() }}

You've added two array hierarchies here... "toArray" already returns an array so you don't need the brackets around it.

{{ $dps->appends($request->all())->links() }}

Does this work?

mbo's avatar
Level 3

Thanks works! thought to difficult..-)

Only challenge i got now i see is that the _token is also given in url. Any idea how i can get that variable out?

thanks in advance!

ftiersch's avatar

No problem, instead of

$request->all()

use

$request->except('_token')

:)

mbo's avatar
Level 3

Thanks! tried pull but doesn't work in view. Except also creates the array.

Thanks for the help!

Please or to participate in this conversation.