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

AydenWH's avatar

Iterating $request

May I know what is the proper way to iterate the $request->all()?

I tried the following method,

foreach($request->all() AS $index => $field) {
  # Return null
  dd($field);

  # Return null
  dd($index);

  # Return null
  dd($field[$index]);

  # Return null
  dd($request->input($index));
}
0 likes
4 replies
burlresearch's avatar

It's just an Array:

print_r( $request->all() );
var_dump( $request->all() );
dd( $request->all() );
2 likes
Snapey's avatar

If you have a proper request object then this should work

foreach($request->all() as $key => $value) {
  
    dump($key, $value);

}

If this does not work, check the source of your $request - you are obviously not sending any data.

If this should be coming from a form, check that all form elements have name= attributes

1 like
robrogers3's avatar

hey. just do dd($_REQUEST) and then you will have your answer.

1 like

Please or to participate in this conversation.