Table builder with data from API rest

Hey! I'm using the table builder in a custom livewire component to create a students table, and I'm querying the data from the models using the query builder notation, the student frequency data came from this same query, and its ok, but the grade information came from an external API call. I was reading about this sushi package that fits perfectly for this kinda of occasion, but I've seen examples of the table being constructed over data that only came from the model that sushi it's applied, in my case, I'm getting the student data from a query and I should connect every student row to a grade that came from the API. So I'm using a ->get() in my ::query() to foreach over all students returned from the query to fetch the grades, but I cannot construct the table after this approach, since I'm not returning an Builder Instance anymore...
2 Replies
calebesantana
calebesantanaOP2y ago
Query code:
if (!empty($this->dataCriacao) && !empty($this->dataPrevistaTermino) && !empty($this->tipoAprofundamento)) {
$query = SolicitacaoRequerimento::select('tb_solicitacao_requerimento.id_solicitacao_requerimento', 'a.nome', 'md.frequencia', 'bbc.course_id', 'bbu.user_id')
->join('tb_aluno AS a', 'tb_solicitacao_requerimento.id_aluno_solicitante', '=', 'a.id_aluno')
->join('tb_requerimento AS rm', 'rm.id_requerimento', '=', 'tb_solicitacao_requerimento.id_requerimento')
->join('tb_status_requerimento AS srm', 'tb_solicitacao_requerimento.id_status_requerimento', '=', 'srm.id_status_requerimento')
->join('tb_matricula_disciplina AS md', 'tb_solicitacao_requerimento.id_matricula_disciplina', '=', 'md.id_matricula_disciplina')
->join('tb_disciplina_professor AS dp', 'md.id_disciplina_professor', '=', 'dp.id_disciplina_professor')
->join('tb_blackboard_course AS bbc', 'dp.id_disciplina_professor', '=', 'bbc.id_disciplina_professor')
->join('tb_blackboard_aluno AS bbu', 'a.id_aluno', '=', 'bbu.id_aluno')
->whereIn('srm.descricao', ['EM ANÁLISE', 'AGUARDANDO']);

if ($this->dataCriacao) {
$query->where('tb_solicitacao_requerimento.data_criacao', '>=', $this->dataCriacao);
}

if ($this->dataPrevistaTermino) {
$query->where('tb_solicitacao_requerimento.data_prevista_termino', '<=', $this->dataPrevistaTermino);
}

if ($this->tipoAprofundamento) {
$query->where('rm.id_requerimento', '=', $this->tipoAprofundamento);
}

$alunos = $query->get();

foreach ($alunos as $aluno) {
// get student grade
}

return $alunos;
}
if (!empty($this->dataCriacao) && !empty($this->dataPrevistaTermino) && !empty($this->tipoAprofundamento)) {
$query = SolicitacaoRequerimento::select('tb_solicitacao_requerimento.id_solicitacao_requerimento', 'a.nome', 'md.frequencia', 'bbc.course_id', 'bbu.user_id')
->join('tb_aluno AS a', 'tb_solicitacao_requerimento.id_aluno_solicitante', '=', 'a.id_aluno')
->join('tb_requerimento AS rm', 'rm.id_requerimento', '=', 'tb_solicitacao_requerimento.id_requerimento')
->join('tb_status_requerimento AS srm', 'tb_solicitacao_requerimento.id_status_requerimento', '=', 'srm.id_status_requerimento')
->join('tb_matricula_disciplina AS md', 'tb_solicitacao_requerimento.id_matricula_disciplina', '=', 'md.id_matricula_disciplina')
->join('tb_disciplina_professor AS dp', 'md.id_disciplina_professor', '=', 'dp.id_disciplina_professor')
->join('tb_blackboard_course AS bbc', 'dp.id_disciplina_professor', '=', 'bbc.id_disciplina_professor')
->join('tb_blackboard_aluno AS bbu', 'a.id_aluno', '=', 'bbu.id_aluno')
->whereIn('srm.descricao', ['EM ANÁLISE', 'AGUARDANDO']);

if ($this->dataCriacao) {
$query->where('tb_solicitacao_requerimento.data_criacao', '>=', $this->dataCriacao);
}

if ($this->dataPrevistaTermino) {
$query->where('tb_solicitacao_requerimento.data_prevista_termino', '<=', $this->dataPrevistaTermino);
}

if ($this->tipoAprofundamento) {
$query->where('rm.id_requerimento', '=', $this->tipoAprofundamento);
}

$alunos = $query->get();

foreach ($alunos as $aluno) {
// get student grade
}

return $alunos;
}
LeandroFerreira
#pt-br
Want results from more Discord servers?
Add your server