I'm trying to get the data from my pivot table.
Right now the way I do it is like this
$sala = Saluser::where('sala_id',$sala->id)->pluck('user_id');
$usuario = User::whereIn('id',$sala)->get();
The drawback is that I must make two inquiries, which in a relationship. one to many, simply applying the With me loads the related data. With eloquent.
but this time is from many to many
which
I have
|Users|
|-----|
|ID |
|Name |
|etc |
-------
|Salusers|
|--------|
|Id |
|user_id |
|sala_id |
|--------|
|Salas |
|------|
|id |
|titulo|
|descri|
|etc |
|------|
My relationships are in this way: from the user model
public function Salas() {
return $this->belongsToMany(Sala::class,'salusers');
}
from the Sala model
public function Salas(){
return $this->belongsToMany(User::class,'salusers');
}
from the pivot.
public function User(){
return $this->belongstoMany(User::class,'user_id');
}
public function Sala(){
return $this->belongstoMany(Sala::class,'sala_id');
}
- In summary
I am sending the room ID:
And I need to get
all the information in a room
with all the users that are registered to the.