I want to update the record in a single field of the table using ajax in the following way:
$('#cerrar').click(function(){
var registro=$('#cerrar').val();
var route="http://127.0.0.1:8000/almacen/compras/"+registro;
var token=$("input[name=_token]").val();
$.ajax({
url:route,
headers:{'X-CSRF-TOKEN':token},
type:'PUT',
dataType:'json',
data:{
estado:2
},
success:function(){
alert('correcto');
}
});
});
where the controller function is like this:
public function cerrar(Request $request, $id){
$compra=compra::find($id);
$compra->fill($request->input('estado'))->save();
return response()->json([
"mensaje"=>"Actualizacion de registro correcto."
]);
}
But the server gives me the answer
Type error: Argument 1 passed to Illuminate \ Database \ Eloquent \ Model :: fill () must be of the type array