1
I own 3 tables that it is necessary to make Join’s to access the information. By the relationship of the Laravel I can create simple relationships, like belongsTo.
I’m trying to access the information from the first table with the id of the third table. In this case, by the id of the table 'agenda_dias' I want to fetch the patient’s name.
pessoas
-- id
-- nome
pacientes
-- id
-- id_pessoa
agenda_dias
-- id
-- id_paciente
In Model Person I created the following function:
public function agendaDiaPaciente()
{
return $this->hasManyThrough(
'Models\AgendaDia', 'App\Models\Paciente',
'pessoa', 'id_paciente', 'id'
)
}
Model of the Patient:
public function pessoa()
{
// Cria vinculo com tabela de pessoas. Inverso de hasOne();
return $this->belongsTo('App\Models\Pessoa', 'id_pessoa');
}
Model da Agendadia:
public function paciente()
{
return $this->belongsTo('App\Models\Paciente', 'id_paciente');
}
1 person can be 1 patient and one patient for having multiple day schedules ? this is the relationship? Put all models in your question?
– novic
A schedule_days has only 1 patient
– Matheus Hahn
so are all relationships 1 to 1 ???
– novic
That’s right, in this example are all related 1:1
– Matheus Hahn