mardi 11 décembre 2018

How to pass an array from the controller to the view Laravel

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]),

    ];
}
return view('view', compact('data'));

View

 @foreach($data as $dat)
    <tr>
        <td width="100">Product</td>
        <td width="50">Quantity</td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
@endforeach

What am I wrong about?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire