【发布时间】:2020-05-29 11:58:32
【问题描述】:
$vegetables = DB::select("select a.id, a.created_at, a.updated_at,a.storeid, a.itemno, a.type, a.vegie from stores a, storenames b where a.storeid = b.storeid");
return view('stores', ['vegetables' => $vegetables]);
我使用上面的代码查询数据库,在查看页面出现如下错误:
@foreach($vegetables as $vegetable)
<tbody>
<tr>
<th scope="row">{{ $vegetable['storeid'] }}</th>
<td>{{ $vegetable['itemno'] }}</td>
<td>{{ $vegetable['type'] }}</td>
<td>{{ $vegetable['vegie'] }}</td>
</tr>
@endforeach
</tbody>
Facade\Ignition\Exceptions\ViewException 不能将 stdClass 类型的对象用作数组
任何帮助将不胜感激。
【问题讨论】:
-
请在查询中添加表名
-
我认为你缺少表名
-
你错了,他用的是表:
from stores a -
@SergheiLeonenco,之前尝试过,但它不起作用
-
你的视图是什么样的?