That a form shows old values if it is to modify

0

You see, I have a table called Formacion:

Schema::create('formacions', function (Blueprint $table) {
        $table->increments('id');
        $table->string('titulo');
        $table->string('grado');
        $table->string('centro');
        $table->boolean('finalizacion');
        $table->unsignedInteger('anyio_finalizacion')->nullable();
        $table->unsignedInteger('user_id');
        $table->foreign('user_id')->references('id')->on('users');
        $table->timestamps();
    });

I have 2 forms for this: The first to create a new training:

@extends('layouts.app')
@section('content')
    <div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Introduzca su formación</div>

                <div class="card-body">
                    <form method="POST" action="nueva_formacion" novalidate>
                        @csrf

                        <input type="hidden" name="user_id" value="{{ auth()->user()->id }}"/>

                        @include('formularios.base.formacion')

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    Introducir Formación
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

And another to modify the form:

@extends('layouts.app')
@section('content')
    <div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Aqui podra modificar su formación de {{$f->titulo}}</div>

                <div class="card-body">
                    <form method="POST" action="{{route('formacion.cambiar',$f)}}" novalidate>
                        @csrf

                        @include('formularios.base.formacion')

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    Actualizar Formación
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

Both forms have the following code with the variables to fill:

<div class="form-group row">
<label for="titulo" class="col-md-4 col-form-label text-md-right">Titulo</label>

<div class="col-md-6">
    <input id="titulo" type="text" class="form-control{{ $errors->has('titulo') ? ' is-invalid' : '' }}" name="titulo" value="{{ old('titulo') }}" required autofocus>

        @if ($errors->has('titulo'))
            <span class="invalid-feedback">
                <strong>{{ $errors->first('titulo') }}</strong>
            </span>
        @endif
    </div>
</div>

<div class="form-group row">
    <label for="grado" class="col-md-4 col-form-label text-md-right">Grado</label>

    <div class="col-md-6">
        <input id="grado" type="text" class="form-control{{ $errors->has('grado') ? ' is-invalid' : '' }}" name="grado" value="{{ old('grado') }}" required autofocus>

        @if ($errors->has('grado'))
            <span class="invalid-feedback">
                <strong>{{ $errors->first('grado') }}</strong>
            </span>
        @endif
    </div>
</div>

<div class="form-group row">
    <label for="centro" class="col-md-4 col-form-label text-md-right">Centro</label>

    <div class="col-md-6">
        <input id="centro" type="text" class="form-control{{ $errors->has('centro') ? ' is-invalid' : '' }}" name="centro" value="{{ old('centro') }}" required autofocus>

        @if ($errors->has('centro'))
            <span class="invalid-feedback">
                <strong>{{ $errors->first('centro') }}</strong>
            </span>
        @endif
    </div>
</div>

<div class="form-group row">
    <label for="finalizacion" class="col-md-4 col-form-label text-md-right">¿Lo llego a finalizar?</label>

    <div class="col-md-6">
        Si<input type="radio" name="finalizacion" value=1 />
        No<input type="radio" name="finalizacion" value=0 checked />

        @if ($errors->has('finalizacion'))
            <span class="invalid-feedback">
                <strong>{{ $errors->first('finalizacion') }}</strong>
            </span>
        @endif
    </div>
</div>

<div class="form-group row">
    <label for="anyio_finalizacion" class="col-md-4 col-form-label text-md-right">Si lo finalizo, ¿En que año?</label>

    <div class="col-md-6">
        <input id="anyio_finalizacion" type="number" class="form-control{{ $errors->has('anyio_finalizacion') ? ' is-invalid' : '' }}" name="anyio_finalizacion" value="{{ old('anyio_finalizacion') }}" required autofocus>

        @if ($errors->has('anyio_finalizacion'))
            <span class="invalid-feedback">
                <strong>{{ $errors->first('anyio_finalizacion') }}</strong>
            </span>
        @endif
    </div>
</div>

Having said all this, what I want to do is that if I use the modification form, the old data in the row should be displayed. Because I recycle the code in both forms, I could for example have the old degree displayed with the value="{{$ f-> grade}}" when I modify it, but if I put it on it will give me an error when using the Form to insert a new training.

    
asked by Miguel Alparez 04.05.2018 в 00:27
source

0 answers