How to make Bootstrap Dynamic Tabs with Portable?

Asked

Viewed 98 times

-3

Goodnight

I am trying to make each Tabs present a specific data referring to the name of a person who in my work would be the name of a teacher

I have the following table diaries

id - nomedoprofessor - aluno   - diadaaula  - resumodaaula
01 - Adriano         - Carlos  - 2020-01-01 - Fez todas as tarefas
02 - Adriano         - Carlos  - 2020-01-02 - Faltou a aula
03 - Adriano         - Carlos  - 2020-01-03 - Chegou atrasado
04 - Adriano         - Carla   - 2020-01-01 - Teve duvidas mas consegui responder
05 - Adriano         - Carla   - 2020-01-02 - Não quis fazer exercícios, estava cansada
06 - Adriano         - Carla   - 2020-01-03 - Foi embora mais cedo
07 - Adriano         - Antônio - 2020-01-01 - Fez todas as tarefas
08 - Adriano         - Antônio - 2020-01-02 - Fez todas as tarefas
09 - Adriano         - Antônio - 2020-01-03 - Faltou por doença

In my controller I have following codes

public function show($professor){
    $alunos = DB::table('diarios')       
    ->where('nomedoprofessor','=', $professor)         
    ->orderBy('aluno')
    ->groupBy('aluno')
    ->get(); 

To filter by teacher

in my views professor.blade.php

<ul class="nav nav-tabs" id="myTab" role="tablist">
@foreach ($alunos as $aluno)                     
  <li class="nav-item">
    <a class="nav-link" id="home-tab" data-toggle="tab" href="#home-{{$aluno->id}}" role="tab" aria-controls="home-{{$aluno->id}}" aria-selected="true">{{$aluno->aluno}}</a>
  </li> 
 @endforeach
 </ul>
 <div class="tab-content" id="myTabContent">
 @foreach ($alunos as $aluno)                
   <?php 
      $conteudo = DB::table('diarios')       
       ->where('nomedoprofessor','=', $aluno->nomedoprofessor)
       ->where('aluno','=',$aluno->aluno)         
       ->orderBy('aluno')        
       ->get();        
    ?>
      <div class="tab-pane fade show" id="home-{{$aluno->id}}" role="tabpanel" aria-labelledby="home-{{$aluno->id}}">
<p>{{$conteudo->diadaaula}} - {{$conteudo->resumodaaula}}</p>
      </div>
      @endforeach
 </div>

But the error is appearing

Property [diadaaula], [resumeroom] does not exist on this Collection instance.

The correct one was to appear as per the image below, can someone please help me.

inserir a descrição da imagem aqui

  • One idea is to use AJAX

  • Code in the View !!!

1 answer

-1

What I will describe below does not answer your question initially, but I demonstrate an architecture problem in your code. As for the error properties, you are probably using the names of the wrong fields.

Don’t use queries in the view, solve this in the model or controller, take this code:

   $conteudo = DB::table('diarios')       
       ->where('nomedoprofessor','=', $aluno->nomedoprofessor)
       ->where('aluno','=',$aluno->aluno)         
       ->orderBy('aluno')        
       ->get();

and migrate to a method of your Student model:

// na classe Aluno crie a propriedade
$conteudo = null;


function getConteudo() {
    // isto para garantir que não estará sempre fazendo a consulta
    // no banco, mesmo quando o modelo já está em memória e este
    // método já foi chamado uma vez
    if ($this->conteudo) {
        return $this->conteudo;
    }

    $this->conteudo = DB::table('diarios')       
       ->where('nomedoprofessor','=', $aluno->nomedoprofessor)
       ->where('aluno','=',$aluno->aluno)         
       ->orderBy('aluno')        
       ->get();

    return $this->conteudo;
}
  • Good Morning Thank you but I actually have to make a new foreach before the div, so I solved my problem, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.