Error: Argument 1 passed to Illuminate \ Database \ Eloquent \ Model :: fill () must be of the type array

1

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

    
asked by ALVARO ROBERTO BACARREZA ARZAB 10.05.2018 в 23:44
source

1 answer

1

The notice that appears tells you that the fill method requires the values that you will pass in the form of an associative array; that is

$valores = array('clave1' => 'valor1', 'clave2' => 'valor2');

Therefore you can handle it in the following way:

$compra->fill(array('estado' => $request->input('estado')));
    
answered by 11.05.2018 / 01:46
source