尝试在数组中打印值时非法字符串偏移
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'
我在邮件模板中呈现视图但在我的视图中我在使用 收到错误: p>
非法字符串偏移'product_name' p>
blockquote>
div> dd时遇到以下错误( $行[ 'PRODUCT_NAME']); 代码>。 我得到产品名称但不在以下代码中不知道此错误的含义: p>
@foreach($ order as $ row)
&lt; tr&gt;
&lt; ; td&gt; {{$ row ['product_name']}}&lt; / td&gt;
&lt; td&gt; {{$ row ['amount']}}&lt; / td&gt;
&lt; td&gt; {{$ row ['quantity']}}&lt; / td&gt;
&lt; / tr&gt;
@ endforeach
code> pre>
$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