so I am trying to loop through an array of objects to update certain values in my database with the values from the object

When I run this loop in my controller

```
foreach($statuses as $status){
            $workflow->statuses()->where('id', $status->id)->update([
                'status' =>  $status->status
            ]);
        };

```

It gives me error `trying to get property of non-object`

When I do a `return response($request->statuses) this is the data structure I see in the console
[![enter image description here](https://i.stack.imgur.com/7Wq6P.png)](https://i.stack.imgur.com/7Wq6P.png)

here is the complete controller

```
public function workflowStatuses(Request $request, Workflow $workflow)
    {

        // validate form data
        $data = $request->validate([
            'workflow' => 'required|string',
        ]);

            // validate form data
        $oldStatuses = $request->validate([
            'statuses' => 'required|array'
        ]);

        // validate form data
        $newStatuses = $request->validate([
            'newStatuses' => 'required|array',
        ]);

        $workflow->update($data);

        $statuses = $oldStatuses;

        foreach($statuses as $status){
            $workflow->statuses()->where('id', $status['id'])->update([
                'status' =>  $status->status
            ]);
        };

        $workflow->statuses()->saveMany($newStatuses);

        return response($workflow, 200);

    }

```