0

I am sending these objects to server to fetch the record and update it. But it is giving me the below given error.

error

Wnen I add dd, I see this message.

dd

FilterController.php

public function update(Request $request, Filter $filter)
{
    $filters = collect($request->filters);
    dd($filters);
    $filters->each(function ($item) use ($request, $filter) {
        if (isset($item['name']) && isset($item['latin'])) {
            $data = [
                'category_id' => $request->category_id,
                'name' => $item['name'],
                'latin' => $item['latin'],
                'field' => $item['field'],
            ];
            $filter_item = Filter::query()->firstOrCreate(['id' => $item['id'] ?? null]);
            $filter_item->fill($data)->save();
        } else {
            return null;
        }
        if (isset($item['value'])) {
            foreach($item['value'] as $value) {
                $filter_item->values()->updateOrCreate(
                    ['id' => $value['id']],
                    ['value' => $value['value']]
                );
            }
        }
    });
    return redirect()->route('filters.index');
}
  • Your $value variable contains the value of blue. As you are iterating through the array and taking it's value to iterate through. So it's not an array. It's a string right now – Rajesh Paudel Dec 03 '21 at 05:36
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – MichalOravec Dec 03 '21 at 08:53

1 Answers1

0

as per your screen short you don't have $value['id']

it will be like

if (isset($item['value'])) {
            foreach($item['value'] as $key => $value) {
                $filter_item->values()->updateOrCreate(
                    ['id' => $key],
                    ['value' => $value]
                );
            }
        }

as $item['value'] is normal array with only index

Kamlesh Paul
  • 11,778
  • 2
  • 20
  • 33