Table from different database connection

I have this Livewire Component which implementing the HasTable, this component should render a table with data from a query that is mainly using this Model that uses protected $connection = 'other_database', this query has multiple joins with tables that are from the same 'other_database'...the thing is that my table its being rendered, it it's paginating and counting the total number of data etc...the only value that it's being showed it's the id_matricula value, all others are not. The query:
$this->alunos = Matricula::select('tb_matricula.id_matricula', 'tb_aluno.ra', 'tb_perfil.nome', 'tb_periodo_letivo.descricao', 'tb_curso_base.nome_para_impressao', 'tb_disciplina.descricao', 'tb_matricula_disciplina.frequencia')
->join('tb_aluno', 'tb_aluno.id_aluno', 'tb_matricula.id_aluno')
->join('tb_matricula_disciplina', 'tb_matricula_disciplina.id_matricula', 'tb_matricula.id_matricula')
->join('tb_disciplina_professor', 'tb_disciplina_professor.id_disciplina_professor', 'tb_matricula_disciplina.id_disciplina_professor')
->join('tb_disciplina', 'tb_disciplina.id_disciplina', 'tb_disciplina_professor.id_disciplina')
->join('tb_curso', 'tb_curso.id_curso', 'tb_matricula.id_curso')
->join('tb_curso_base', 'tb_curso_base.id_curso_base', 'tb_curso.id_curso_base')
->join('tb_turma', 'tb_turma.id_turma', 'tb_matricula.id_turma')
->join('tb_perfil', 'tb_perfil.id_perfil', 'tb_aluno.id_perfil')
->join('tb_periodo_letivo', 'tb_periodo_letivo.id_periodo_letivo', 'tb_matricula.id_periodo_letivo')
->where('tb_matricula.id_periodo_letivo', '=', $this->periodo_letivo)
->where('tb_curso_base.id_curso_base', '=', $this->curso)
->where('tb_disciplina.id_disciplina', '=', $this->disciplina)
->get();
$this->alunos = Matricula::select('tb_matricula.id_matricula', 'tb_aluno.ra', 'tb_perfil.nome', 'tb_periodo_letivo.descricao', 'tb_curso_base.nome_para_impressao', 'tb_disciplina.descricao', 'tb_matricula_disciplina.frequencia')
->join('tb_aluno', 'tb_aluno.id_aluno', 'tb_matricula.id_aluno')
->join('tb_matricula_disciplina', 'tb_matricula_disciplina.id_matricula', 'tb_matricula.id_matricula')
->join('tb_disciplina_professor', 'tb_disciplina_professor.id_disciplina_professor', 'tb_matricula_disciplina.id_disciplina_professor')
->join('tb_disciplina', 'tb_disciplina.id_disciplina', 'tb_disciplina_professor.id_disciplina')
->join('tb_curso', 'tb_curso.id_curso', 'tb_matricula.id_curso')
->join('tb_curso_base', 'tb_curso_base.id_curso_base', 'tb_curso.id_curso_base')
->join('tb_turma', 'tb_turma.id_turma', 'tb_matricula.id_turma')
->join('tb_perfil', 'tb_perfil.id_perfil', 'tb_aluno.id_perfil')
->join('tb_periodo_letivo', 'tb_periodo_letivo.id_periodo_letivo', 'tb_matricula.id_periodo_letivo')
->where('tb_matricula.id_periodo_letivo', '=', $this->periodo_letivo)
->where('tb_curso_base.id_curso_base', '=', $this->curso)
->where('tb_disciplina.id_disciplina', '=', $this->disciplina)
->get();
7 Replies
Dan Harrin
Dan Harrin2y ago
you have probably forgotten to select the correct columns i would really advise you to avoid these joins, they are all so simple and you can do it much cleaner and easier with relationships
calebesantana
calebesantanaOP2y ago
When I dd($this->alunos) it's showing the correct model properties, exactly like the select in this query, but when I use this values in the getTableColumns() it's not rendering...where I'm forgotten to select? Maybe it's necessary to create the relationships and try to access the values from the relation?
Dan Harrin
Dan Harrin2y ago
theres literally no point using the joins if you have relationships defined
calebesantana
calebesantanaOP2y ago
Ok, but in the query way It should work anyway, right? Here's the dd of getTableQuery() method:
protected function getTableQuery(): Builder
{
dd($this->alunos);
return $this->alunos->toQuery();
}
protected function getTableQuery(): Builder
{
dd($this->alunos);
return $this->alunos->toQuery();
}
Dan Harrin
Dan Harrin2y ago
no... just return the query from getTableQuery() without get() using toQuery() will not work you will lose the joins
calebesantana
calebesantanaOP2y ago
Ohhh okay! Thanks
Want results from more Discord servers?
Add your server