Skip to content
Advertisement

Not able to get array variable contents after passing them from controller to views

I am passing array after decoding it from controller to views.

AddressController.php

$pro = $request->input('pro');
$pro_array = json_decode($pro, true);

    Mail::send('emails.send', ['title' => $title,'pro_array' => $pro_array, 'email' => $email, 'fname' => $fname,
        'lname' => $lname, 'addressline' => $addressline, 'Ttl' => $Ttl, 'phone' => $phone], function ($message) use ($email)
    {
        $message->from($email);
        $message->to('info@phalwala.com', 'Phalwala');
        $message->subject("Welcome To Phalwala");

    });
return redirect('/')

I only want name, price and quantity from the array but it is giving Trying to get property of non-object.

send.blade.php

@foreach($pro_array as $cartItem)
    <p>Products: {{$cartItem->name}}</p>
    <p>Unit Price: {{$cartItems->price}} X {{$cartItems->qty}}</p>
    @endforeach

Advertisement

Answer

Just access the key instead of trying to acces it like object:

@foreach($pro_array as $cartItem)
    <p>Products: {{$cartItem['name']}}</p>
    <p>Unit Price: {{$cartItems['price']}} X {{$cartItems['qty']}}</p>
@endforeach
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement