I have 3 tables that you need to join to access the information. By the relation of Laravel
I can create simple relations, such as belongsTo
.
I'm trying to access the information from the first table with the id of the third table. In case, by the id of the table_days_timebook I want to search the patient's name.
pessoas
-- id
-- nome
pacientes
-- id
-- id_pessoa
agenda_dias
-- id
-- id_paciente
In Person Model I created the following function:
public function agendaDiaPaciente()
{
return $this->hasManyThrough(
'Models\AgendaDia', 'App\Models\Paciente',
'pessoa', 'id_paciente', 'id'
)
}
Patient Model:
public function pessoa()
{
// Cria vinculo com tabela de pessoas. Inverso de hasOne();
return $this->belongsTo('App\Models\Pessoa', 'id_pessoa');
}
DayDay Model:
public function paciente()
{
return $this->belongsTo('App\Models\Paciente', 'id_paciente');
}