【发布时间】:2021-12-21 00:23:31
【问题描述】:
我有 2 个表格、资产和历史。在表 phistories 中将带有asset_id。 我想显示所选资产 ID 下的历史列表。 到目前为止我在 AssetController 中尝试过的内容:
public function edit(Asset $asset)
{
$phistories = (DB::table('phistories')->where('asset_id',$asset)->get());
return view('assets.editAsset',[
'asset' => $asset,
'phistories' => $phistories
]);
}
这是我的看法
@foreach($phistories as $phistory)
<tr>
<td>{{$phistory->id}}</td>
<td><a href="/edit/{{$phistory->id}}/editPhistory"><span>{{$phistory->phistory_name}}</span></a>
</td>
<td>{{$phistory->phistory_category}}</td>
<td>{{$phistory->phistory_pic}}</td>
</tr>
@endforeach
我的问题是它没有在视图中显示任何内容。谁能检查我的查询是否正确或我使用了错误的方法?
【问题讨论】:
-
你可以使用关系或加入
标签: php mysql list view laravel-8