I have following models and controller.
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
the above code retursn
name Reporting Person
========================================================
Ankur /*gets from user table*/ 35 //gets from reporting table
the name of reporting person is Yadav and this name is in users table how i replace the Reporting person id 35 to name Yadav in view