Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal string offset while trying print the value with in the array

I am rendering view in mail template but in my view I am getting following error when I use dd($row['product_name']);. I get product name but not in following code don't know meaning of this error:

@foreach ($order as $row)
    <tr>
        <td>{{ $row['product_name'] }}</td>
        <td>{{ $row['amount'] }}</td>
        <td>{{ $row['quantity'] }}</td>

    </tr>
@endforeach

getting error:

Illegal string offset 'product_name'

like image 375
Pranav Mandlik Avatar asked Apr 02 '26 05:04

Pranav Mandlik


2 Answers

$order is an object $row->product_name and not an array $row['product_name'].

@foreach ($order as $row)
    <tr>
        <td>{{ $row->product_name }}</td>
        <td>{{ $row->amount }}</td>
        <td>{{ $row->quantity }}</td>
    </tr>
@endforeach
like image 82
Bas Avatar answered Apr 03 '26 21:04

Bas


It might be because of 'product_name' key is not exist in your array element. Before using it, check is that key exist in that array element with isset

@foreach ($order as $row)
        <tr>
            <td>{{ isset($row['product_name'])?$row['product_name']:'' }}</td>

        </tr> @endforeach
like image 39
Ranjit Shinde Avatar answered Apr 03 '26 20:04

Ranjit Shinde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!