我有以下型号和控制器。
user.php的
public function reporting()
{
return $this->hasMany('App\Reporting','user_id','id');
}
RegisterController.php
public function viewUsers()
{
$users = User::with('reporting')->get();
return view('users',compact('users'));
}
users.blade.php
@foreach($users as $user)
<tr>
<td>{{$user->name}}</td>
<td>
@foreach($user->reporting as $report)
{{$report->reporting}}
@endforeach
</td>
</tr>
@endforeach
上面的代码重新编写
name Reporting Person
========================================================
Ankur /*gets from user table*/ 35 //gets from reporting table
报告人的姓名是Yadav,此名称在用户表中如何替换报告人员ID 35以在视图中命名Yadav