Hello, I am doing some tests in which I intend to go through some forms with various texts, in which I manage to get the information correctly, but when it comes to modifying and saving it, it is not doing it correctly, I leave you part of the code.
Controller
public function update(Request $request, $id)
{
//
$textos=Texto::findOrFail($id);
$textos->update($request->all());
$textos->save();
Toastr::success("Se ha actualizado correctamente la $textos->texto");
return Redirect::to('entradas');
}
View
<section class="content">
<div class="row">
<div class="box-header with-border">
<h3 class="box-title">Editar Textos</h3>
</div>
@foreach($textos as $listado)
<div class="col-md-6">
<div class="box box-primary">
{{ Form::model($listado, ['method' => 'post' , 'files' => true , 'route' => ['entradas.update',$listado->id]]) }}
@method('PUT')
<div class="form-group">
{{ Form::label('texto', 'Texto') }}
{{ Form::textarea('texto', $listado->texto, array("class" =>"form-control")) }}
</div>
<div class="box-footer">
{{ Form::submit('Guardar', array("class" => "btn btn-primary")) }}
{{ Form::reset('Reset', array("class" => "btn btn-primary")) }}
</div>
</div>
</div>
@endforeach
</div>
</section>
You have a detail here and it is that the update method is not used like this, according to the Laravel Updates documentation you can use the save method both to create and to update, in your case you want to edit all the properties of the entity with what you It comes from the request of the form, for this we use the fill method as explained here Mass assignment of properties :
You must take into account that for this to work the entity must have a property called "fillable" which is an array with the name of the fields that can be edited, otherwise nothing will be modified:
After modifying the properties, the entity is saved: