How to make a call list with radiobox with the Lockbox?

Asked

Viewed 327 times

0

Hello, I’m a beginner in Lisbon and I’m doing a project for a school whose one of the features of the project is to make a attendance list of students. Where will be listed the students of a particular class in a table that will have the radio box fields to mark the presence or absence of each student. I’m having a hard time in this part of listing students and marking their presence. I had done a class Frequencia_conteudo.phpwhere it had the attributes (turma_id, aluno_id, atividades_ministadas, presenca, data) only that I decided to dismember this class by making one of Conteudo and another of Presenca where each has its own attributes (turma_id, atividades_ministardas, data) and (turma_id, conteudo_id, aluno_id, presenca). What is said about Conteudo is already ready and working properly, but when submitting the inclusion of the content I am already asking to redirect to the "call list", I show below the store of Conteudocontroller:

public function store(ConteudoRequest $request){
    $novo_frequencia = $request->all();
    Conteudo::create($novo_frequencia);
    return view('presenca.create');
}

In the Presence controller is the create method:

public function create($turma_id){
    Conteudo::find($turma_id);
    $presenca = Conteudo::query()
        ->join('turmas', 'turmas.id', '=', 'conteudos.turma_id')
        ->join('turmas', 'turmas.id', '=', 'turma_alunos.turma_id')
        ->where('turmas.id', '=', $turma_id)->get();
    return view ('presenca.create', ['presenca'=> $presenca]);
}

I asked you to pull the id of the class that was registered the Content, and I did this query to find the students of the selected class who are saved in turma_alunos. The Presence create view looks like this:

@extends('app')

@section('content')
<!-- Fonts -->
<div class="container">
    <div class="row">
        <div class="col-sm-9">
            <div class="box box-primary">

            <div class="box-header">
                    <h3 class="box-title">Lista de Presença</h3>
                        <div class="col-sm-6">
                            <label>Turma: </label>
                            <label>{{$presenca->turma->descricao}}</label></div>

                            <label>Professor Responsável: </label>
                            <label>{{$presenca->turma->oficina->professor->nome}}/label>
                    </div>

                <div class="box-body">
                    <div class="table-responsive">
                        <input action="{{route('presenca.store')}}" method="post" id="presenca">
                        <table class="table table-striped table-bordered table-hover" >
                            <thead>
                            <tr bgcolor="#F0F0F0">
                                <th>Aluno</th>
                                <th>Presença</th>
                            </tr>

                            </thead>
                            <tbody>
                          @foreach($presenca as $alu)
                                <tr>
                                    <td id="aluno_id">{{$alu->aluno->nome}}</td>
                                    <td id="presenca">
                                    <td><input type="radio" name="presenca" id="presenca" value="P" checked>Presente</td>
                                    <td><input type="radio" name="presenca" id="presenca" value="A">Ausente</td>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                            <input type="submit" class="btn btn-success" value="Finalizar">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

But when I go to test it the Variable returns me this error:

Undefined variable: presenca (View: C: Users Winseven Desktop sischool Resources views Presenca create.blade.php)

Even though I passed the $presencawhen I call the view. I don’t know if that would be the mistake, or if I did something wrong, any help is welcome!

ps: I am using Laravel 5.5 and PHP 7.0.10

1 answer

0


Change

return view ('presenca.create', ['presenca'=> $presenca]);

For

return view ('presenca.create')->with('prensenca',$presenca);

And in the view just at the beginning to debug, use a

@php
    dd(presenca);
    exit;
@endphp
  • I tried to do what you suggested and now I got the error: Use of Undefined Constant presenca - assumed 'presenca' (View: C: Users Winseven Desktop sischool sources views Presenca create.blade.php)

  • The possibility that your query is wrong, focus on debugging it first, using dd(), inside the controller

  • Really my consultation was in error, thank you very much Lucas!

Browser other questions tagged

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