petritr
33
19
Laravel

Problem with foreach on update/save

Posted 2 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.