Undefined array key "consignee_lastName"
@foreach ($data as $value) {{ $value['consignee_lastName']}} @endforeach
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi I'm trying to foreach in the view over the data in the session. I get a foreach () argument argument must be of type array | object, string given. Thank you
if (!$request->session()->exists('formData')) {
$request->session()->put('formData', ['Data', $request->all()]);
} else {
$request->session()->push('formData', ['Data', $request->all()]);
}
public function index()
{
$product = Product::get();
$data = array(session('formData'));
return view('cart.index', [
'product' => $product,
'data' => $data
]);
}
@foreach ($data as $value)
{{ $value->consignee_lastName }}
@endforeach
Please or to participate in this conversation.