I have three tables: Tournaments, Participants, Users. The structure is:
Tournaments:
-Id
-Description
-Date
Participants
-Id
-Id_tourn
-Id_user
Users
-Id
-Name
On my blade template I need all the info from Tournaments table and info of the User which is the participant of that tournament.
I've created the relation between Tournaments and User Models.
UPDATE:
Tournaments Model:
public function users() {
return $this->belongsToMany('App\User', 'Participants', 'Id_tourn', 'Id_user');
}
public function getTournaments()
{
return $this->with('users')->get();
}
Tournament Controller:
public function show()
{
$tourns = new Tournaments();
$tournaments = $tourns->getTournaments();
return $tournaments;
}
but when I try $tournament->users in foreach loop it returns 0 results
Thanks a lot!