0
votes

I'm validating laravel forms and old input does not preserve after validation fail.

I'm using laravel 5.8 form request validation and html input fields are filled with default values :

public function store(ProyectoRequest $request){
    $input = $request->validated();

    DB::transaction(function () use($input) {
        $proyecto = new Proyecto();
        $proyecto->fill($input);
        $proyecto->save();
    });

    return redirect(route('proyectos.index'));
}
<div class="form-group">
     <label for="nombre">Nombre</label>
     <input type="text" class="form-control input-lg" value="{{$proyecto_nombre}}" name="nombre">
</div>

When the form is validated the page reloads with the default values. I expect that input fields values are preserved. That is what I have understood from the documentation.

1

1 Answers

2
votes

I am looking for the docs and there is not written if this is the normal behaviour or not.

Anyway you can do yourself with this code:

 <div class="form-group">
     <label for="nombre">Nombre</label>
     <input type="text" class="form-control input-lg" value="{{ old('proyecto_nombre', $proyecto_nombre) }}" name="nombre">
</div>

In laravel the old function retrieves input fields.