How can I show the name of user using a foreign key? I have 2 tables: users and departements, one departement have only one cheif and a user can be a cheif of only one departement. So I think it's a "one to one relationship". the departement table have the"user_id" as a foreign key from the table users. In the vue I have:
<tr v-for="departement in departements" :key="id" >
<td>{{departement.id }}</td>
<td>{{departement.name }}</td>
<td>{{departement.user_id }}</td>
<td>{{departement.bio }}</td>
I want to display the name of the user from users table who has the user_id. Thank you.
Dosen't work Department Controller:
public function index()
{
return Departement::where('name','!=','admin')->latest()->paginate(100);
$departements = Departement::with('chief')->get();
return response()->ajax($departements, 200);
}
am i right?