How to loop arrays in laravel controller?

  laravel, php

i am trying to loop the array with foreach in controller it is going as [object object]

the error says invalid argument supplied for foreach()

below is the type of array i am having

[{ result: 45, test_id: 1 }, { result: null, test_id: 2 }]

Here is my code

foreach ($request->tests as $test) {
  $data = new Test();
  $data->test_id = $test->test_id;
  $data->result = $test->result;

Source: Laravel

Leave a Reply