我想在過去24小時內顯示10個存入和取出金額的人。我能夠在那裏顯示user_id和金額,但我想用戶名而不是user_id。如何從Laravel的用戶標識中獲取用戶名?
它正在爲基金不退出
我在$資金沒有名字科拉姆和$ withdrae它是在用戶我有這樣的代碼:
<div class="col-md-6">
<div class="text-center"><h4 class="text-success">Last 10 Investors</h4></div>
<table class="table text-white" >
<tbody>
@foreach(\App\Fund::where('created_at', '>', \Carbon\Carbon::now()->subHours(24))->orderBy('id', 'DESC')->take(10)->get() as $fund)
<tr>
<th scope="row"></th>
<td>{{ $fund->user_id }}</td>
<td class="text-center text-warning">{{ $fund->total }}</td>
<td class="text-right"><img src="https://adsok.com/img/btc.png" alt="Bitcoin"> <i><b>bitcoin</b></i><br></td><br>
</tr>@endforeach
</tbody>
</table>
。
對於退出
<div class="col-md-6">
<div class="text-center"><h4 class="text-success">Last 10 Investors</h4></div>
<table class="table text-white" >
<tbody>
@foreach(\App\Withdraw::where('created_at', '>', \Carbon\Carbon::now()->subHours(24))->orderBy('id', 'DESC')->take(10)->get() as $withdraw)
<tr>
<th scope="row"></th>
<td>{{ $withdraw->user_id }}</td>
<td class="text-center text-warning">{{ $withdraw->total }}</td>
<td class="text-right"><img src="https://adsok.com/img/btc.png" alt="Bitcoin"> <i><b>bitcoin</b></i><br></td><br>
</tr>@endforeach
</tbody>
</table>
。
我已經在這兩個基金粘貼同樣的關係,並退出模型
public function user()
{
return $this->belongsTo('App\User', 'user_id');}
如果你已經設置了用戶關係,你可以用'$ fund-> user-> id'或'$ fund-> user-> name'來調用用戶數據。如[此處]所述(https://laravel.com/docs/5.5/eloquent-relationships#one-to-many-inverse)。 – vozaldi