Bug checking if there is a record if the button is disabled - LARAVEL

0

I'm having a bug it is not verifying correctly whether or not there is a related table record, it always comes from the current table and not from the other table

DATA YOU SHOULD CHECK IF YOU EXIST IN THE RENEWAL TABLE (nomerespo, nomealuno)

Ex: User requests a renewal and clicks on confirm ok, in case you want to return to the card he sees that the button has changed the name and is "subscribed" I did exactly that and I was not successful he brings the button with name inscribed without having done the registration before, follow the code below

- Model Registration

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Matricula extends Model
{
    protected $table = 'matricula';
    protected $fillable = ['user_id','nomealuno','nomedopai']; // user_id salva id do usuario quando cria uma matricula la tem um campo de email e nele eu posso visualizar no card renovação o nome do pai e do filhos cadastrados 


    public function user() {
        return $this->belongsTo('App\User');
    }   

    public function renovacao() {
        return $this->hasMany('App\Renovacao');

    }  
}

- Model Renovation

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;

class Renovacao extends Model
{
    protected $table = 'renovacao';
    protected $fillable = ['nomerespo','nomealuno','status'];


    public function matricula() {
        return $this->belongsTo('App\Matricula');
    }
}

- Controller

public function listardados()
{ //Pega os registro cadastrado do usuario logado e joga no form 

    $matricula = Matricula::where('user_id', Auth::id())->get();

    //dd($matricula);
    return view('dashboard.renovacao.teste', compact( 'matricula'));
}

public function store(RenovacaoRequest $request){ // função salva no banco de dados 


    $user = Auth()->user();

    $dados = $request->get('rematricula');

    foreach ($dados as $key => $dado) {

        Renovacao::create($dado);
    }


    return view('dashboard.renovacao.confirmacao', compact ('renovacao'));
}

- Migration Enrollment

public function up()
{
    Schema::create('matricula', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users');
        $table->string('nomealuno');
        $table->string('nomedopai');
        $table->timestamps();

    });
}

- MIgration renewal

public function up()
{
    Schema::create('renovacao', function (Blueprint $table) {
        $table->increments('id');
        $table->string('nomerespo');
        $table->string('nomealuno');
        $table->string('status')->default('pendente');
        $table->timestamps();
    });
}

- FORM

<form class="form-horizontal " id="regForm" action="{{route('renovacao.store')}}" method="POST">
        <div class="card-panel white">
            <h4 class="center">Solicitar Renovação</h4>
            <div class="row"></div>
            {{ csrf_field()}}

            <div class="row">
                @if($matricula->count())
                    <right>
                        <a>**Dados Cadastrados**</a>
                    </right>
                    <div class="row"></div>
                    <div class="row"></div>
                    @foreach($matricula as $matric)

                        <div class="row">
                            <div class="col s6 m6">
                            <div class="input-field {{$errors->has('') ? 'has-error' : ''}} ">
                                <label for="produto">Nome do Pai:</label>
                                <input type="text" class="form-control" name="rematricula[{{ $loop->index}}][nomerespo]" value="{{ $matric->nomedopai }}">
                            </div>
                            </div>

                            <div class="col s6 m6">
                            <div class="input-field {{$errors->has('') ? 'has-error' : ''}} ">
                                <label for="produto">Nome do Aluno(a):</label>
                                <input type="text" class="form-control" name="rematricula[{{ $loop->index}}][nomealuno]" value="{{ $matric->nomealuno }}">
                            </div>
                            </div>

                        </div>

                    @endforeach
                    <div class="col s12 m6">
                        <div class="row"></div>
                        <div class="row"></div>
                        <div class="row">
                            <div>
                                <div class="card-panel white ">
                                    <b class="black-text">AVISO? </b></br></br>
                                    <span>• Aviso</span></br></br>

                                </div>
                            </div>
                        </div>
                        <div class="row">
                        </div>
                    </div>


                    <div class = "row">
                        <div class="col s12">

                            <a title="Voltar Para Página Principal" class="btn orange darken-4 btn-info left " href="/admin">Voltar
                                <i class="material-icons left">arrow_back_ios</i>
                            </a>

                            @if(empty($matric->renovacao()))
                                <button type="submit" class="btn orange darken-4 btn-info right">Confirmar
                                    <i class="material-icons left">save</i>
                                </button>
                            @else
                                <button type="submit" disabled class="btn orange darken-4 btn-info right">Inscrito
                                        <i class="material-icons left">confirmation_number</i>
                                </button>
                            @endif
                        </div>
                    </div>
                @else
                    <div class="row"></div>
                    <div class="row"></div>
                    <p> Desculpe! Página Indisponivel</p>
                    <div class="row"></div>
                    <div class="row"></div>
                    <div class="row"></div>
                    <div class="row"></div>
                    <a title="Voltar Para Página Principal" class="btn orange darken-4 btn-info left " href="/admin">Voltar
                                <i class="material-icons left">arrow_back_ios</i>
                    </a>
                @endif



            </div>
        </div>  
    </form>
    
asked by anonymous 07.12.2018 / 19:42

0 answers