尝试在数组中打印值时非法字符串偏移

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'

$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

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

Try this one:

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

        </tr>
@endforeach

Check out the laravel documentation for blade https://laravel.com/docs/5.6/blade

Can you try this solution

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

        </tr>
@endforeach

add dd($row) insted of dd($row['product_name']).

Your Controller returns Object not Array so you try like that

@foreach ($order as $row)
    <tr>
        <td>{{ $row->product_name }}</td>
        <td>{{ $row->amount }}</td>
        <td>{{ $row->quantity }}</td>
    </tr>
@endforeach

</div>

$order is an object you can not use it like an array

@foreach ($order as $row)
    <tr>
        <td>{{ $row->product_name }}</td>
        <td>{{ $row->amount }}</td>
        <td>{{ $row->quantity }}</td>
    </tr>
@endforeach

If you want to to use the record like this then you need to convert the object toArray()

$order =  $order->toArray();

After that you can use like this: $row['product_name']

here $order is an object so you cant use like $row['product_name'].you can use the property of an object using -> operator. so try like this

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

        </tr>
@endforeach