Keep data already filled in the form

0

When I bring in the form for the user to fill in, I need that if the data already exists in the database, it will bring me the completed form with the possibility of the user "editing", but always creating a new record and not changing the already existing.

Note: It is not the same as using {{old('campo')}} because it is only for a request that gives error. Thanks in advance for your help.

<label for="peso">Peso (Kg) : </label>
<input type="text" name="peso" class="form-control" v-model="peso"/>
<label for="altura">Altura (m) : </label>
<input type="text" name="altura" class="form-control" v-model="altura" v-mask="'#.##'"/>
<label for="peso">Idade: </label>
<input type="text" name="idade" class="form-control" v-model="idade"/>
<br/>
    
asked by anonymous 28.09.2017 / 00:04

1 answer

1

There is the replicate method of the Model that can help you, it creates a model clone that does not exist in the database. ( link )

Let's say your model is Informacoes , in the controller you can check if data already exists in the database and then you replicate the last information.

//Exemplo 
public function metodoDoController() {
    $informacao = $usuario->ultimaInformacao();
    $informacao = $informacao->replicate();
    return view('SUA_VIEW', compact('informacao'));
}
    
28.09.2017 / 13:33