I have a consult, I need to pass the data of an array in the controller to the view, but when I get the data from the array in the view it gives me an error.

```
"Illegal string offset 'name'

```

Controller

```
for($i=0; $i < count($num); $i++) {

    $data = [ 
        'name' => $input['name'][$i],
        'price' => $input['price'][$i],
        'quantity' => intval($input['quantity'][$i]),
        'created_at'=>$now, 
        'updated_at'=>$now,
    ];
}
return view('view', compact('data'));

```

View

```
 @foreach($data as $dat)
    <tr>
        <td width="100">Product</td>
        <td width="50">Quantity</td>
    </tr>
    <tr>
        <td>{{ $dat['name'] }}</td>
        <td>{{ $dat['quantity'] }}</td>
    </tr>
@endforeach

```

dd($data)

```
array:5 [▼
  "name" => "name1"
  "price" => "14.00"
  "quantity" => 1
  "created_at" => "2018-12-11 09:03:35"
  "updated_at" => "2018-12-11 09:03:35"
]

```

What am I wrong about?