How to make a radiobox call list with laravel?

0

Hello, I'm a beginner at laravel and I'm doing a project for a school whose one of the features of the project is to make a list of student presence. Where students from a given class will be listed 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 have made a Frequencia_conteudo.php class where I had the attributes (turma_id, aluno_id, atividades_ministadas, presenca, data) only I decided to break this class by making one of Conteudo and another of Presenca where each one has the respective attributes (turma_id, atividades_ministardas, data) and (turma_id, conteudo_id, aluno_id, presenca) . What is said about Conteudo is already ready and working correctly, but when submitting the inclusion of the content I am already asking to redirect to the "call list", I show below the store of the ContentController:

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

In the Presence controller is the method of create:

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 to pull the id of the class that was registered the Content, and I made this query to search the students of the selected class that are saved in turma_alunos . The view of the create of Presence 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 test it, the laravel returns this error:

Undefined variable: Presence (View: C: \ Users \ WinSeven \ Desktop \ sischool \ resources \ views \ Presenca \ create.blade.php)

Even though I pass $presenca when I call the view. I do not know if this is the mistake, or if I did something wrong, any help is welcome!

ps: I'm using Laravel 5.5 and PHP 7.0.10

    
asked by anonymous 30.11.2017 / 14:28

1 answer

0

Switch

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

By

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

And in the view right at the beginning to debug, use

@php
    dd(presenca);
    exit;
@endphp
    
30.11.2017 / 15:08