petritr
91
19
Laravel

Problem with foreach on update/save

Posted 5 months ago by petritr

I have the following array on dd():

array:2 [
  "data" => array:2 [
    0 => array:2 [
      "name" => "Hub Name"
      "value" => "100"
    ]
    1 => array:2 [
      "name" => "Hub Two"
      "value" => "200"
    ]
  ]
  "hub_id" => "1"
]

I will get invalid foreach:

        foreach ($hubs as $hub) {
            foreach($hub as $values) {

                $hub = Hub::find($hub_id);

                $hub->name = $values["value"];
                $hub->save();
            }
        }

The error: "Invalid argument supplied for foreach()"

What im doing wrong ?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.