search

Home  >  Q&A  >  body text

How to add foreach to Request $request in Controller

I have a post route and I want to add a foreach loop to the request like this:

public function updateProductAttrsInfo(Request $request, $id)
    {
        foreach($request as $req){
            dd($req);
        }
    }

But this is wrong because $request is an object and not an array, so foreach cannot be applied to it.

So I'm wondering how to properly apply foreach to this $request?

P粉803527801P粉803527801230 days ago312

reply all(1)I'll reply

  • P粉488464731

    P粉4884647312024-03-29 09:33:05

    You can try this:

    foreach($request->all() as $k => $v){}

    reply
    0
  • Cancelreply