【发布时间】:2018-06-30 03:08:46
【问题描述】:
我有 2 个表,第一个 fund 第二个 users 我在 users 表中注册了会员名称,而在 fund 表 user_id 中注册了会员。我想在可以显示其user_id 的表格中显示用户名。
<div class="deposit-body">
<table class="table main-table">
<tbody>
<tr class="head">
<th>Name</th>
<th>Date</th>
<th>Currency</th>
<th>Amount</th>
</tr>
@foreachFund::with('user')->where('created_at', '>', Carbon::now()->subHours(24))->orderBy('id', 'desc')->take(10)->get()
<tr>
<td>{{ $fund->user_id }}</td>
<td>{{ $fund->updated_at}}</td>
<td><strong>{{$basic->currency}}</strong></td>
<td><strong>{{ $fund->total }}</strong></td>
</tr>
@endforeach
</tbody>
</table>
</div>
我已将以下代码粘贴到我的基金模型中。但它不起作用。
public function user(){
return $this->belongsTo('App\User', 'user_id');
}
【问题讨论】: