I need to display the name of the doctor who requested a patient report, but with Laravel I tried to show this information in View like this:
{{laudo->paciente->medico->nome}}
Then I received the error message:
Trying to get property of non-object
How do I query using Query Builder at the beginning of this query:
select m.nome from medicos m, pacientes p, laudos l where m.id=p.medico_id and p.id=l.paciente_id and l.id=5;
Medical Class
class Medico extends Model{
//
protected $fillable = [
"nome", "crm", "email", "datanascimento", "senha"
];
protected $table = 'medicos';
public function pacientes(){
return $this->hasMany('App\Paciente');
}
}
Class Patient
class Paciente extends Model{
//
protected $fillable = [
"medico_id", "nome", "rg", "email", "datanascimento", "senha"
];
protected $table = 'pacientes';
public function medico(){
return $this->belongsTo('App\Medico', 'medico_id');
}
public function laudos(){
return $this->hasMany('App\Laudo');
}
}
Class Award
class Laudo extends Model{
//
protected $fillable = [
"codigo", "paciente_id", "nome_arquivo", "data_emicao"
];
protected $table = 'laudos';
public function paciente(){
return $this->belongsTo('App\Paciente', 'id');
}
}