【发布时间】:2019-08-18 19:12:50
【问题描述】:
我有 3 个表,名称是:用户、机器、维护。这个架构像这样
*用户
标识 |姓名 |电子邮件 |密码 | created_at |更新时间
1 |约翰 |一个@邮箱 | ******* 等
*机器
标识 |名称机器 | created_at |更新时间
1 |震惊 | .....等等
*维护
标识 |机器_id |用户 ID |问题 |状态 | created_at | 更新时间
1 | .........1........ |........1......| blablabla 等等 ..
现在我想在表“维护”上显示数据,显示数据“名称”(用户表)和 name_machine(机器表)按 id。
这是我的控制器和我的视图
public function show($id)
{
$maintance = Maintance::all();
return view('users.view',['maintance' => $maintance]);
}
我的看法
<table class="table table-hover">
<tbody><tr>
<th>Machine</th>
<th>Question</th>
<th>User Input</th>
<th>Action</th>
<th>Tanggal</th>
</tr>
@foreach ($maintance as $i)
<tr>
<td>{{ $i->machine_id}} </td>// i want to show name machine here
<td>{{ $i->Question}}</td>
<td>{{ $i->user_id}}</td> // name users to
<td><span class="label label-primary">Lihat Data</span></td>
<td>{{ $i->created_at}}</td>
</tr>
@endforeach
</tbody></table>
此视图数据没有错误,但我不知道如何从不同的表中显示此数据。有人可以帮忙吗?
【问题讨论】:
标签: laravel model controller relation