error when saving an order detail in laravel, it tells me no existing column

0

I am using laravel to create an ordering system and when I save an order it generates an error:

"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'stock' in 'field list' (SQL: insert into 'detalle_pedidos' ('idpedido', 'idproducto', 'cantidad', 'precio') values (7, 20, 4, 24395000.00))"

The issue is that the stock column does not exist in this table. The detail_demand table has the attributes: requisite, idproduct, quantity and price.

Next I will place the function where I keep order detail:

public function store(Request $request)
    {
        if (!$request->ajax()) return redirect('/');

        try{
            DB::beginTransaction();

            $mytime= Carbon::now('America/Caracas');

            $pedido = new Pedido();
            $pedido->idcliente = $request->idcliente;
            $pedido->idusuario = \Auth::user()->id;
            $pedido->tipo_comprobante = $request->tipo_comprobante;
            $pedido->serie_comprobante = $request->serie_comprobante;
            $pedido->num_comprobante = $request->num_comprobante;
            $pedido->fecha_hora = $mytime->toDateString();
            $pedido->impuesto = $request->impuesto;
            $pedido->total = $request->total;
            $pedido->estado = 'pendiente';
            $pedido->save();

            $detalles = $request->data;//Array de detalles
            //Recorro todos los elementos

            foreach($detalles as $ep=>$det)
            {  
                echo "prueba";
                print_r($det);
                echo "prueba";
                $detalle = new DetallePedido();
                $detalle->idpedido = $pedido->id;
                $detalle->idproducto = $det['idproducto'];
                $detalle->cantidad = $det['cantidad'];
                $detalle->precio = $det['precio'];
                echo "impresion detalle";
                print_r($detalle);
                echo "impresion detalle";
                $detalle->save();
            }          

            DB::commit();
        } catch (Exception $e){
            DB::rollBack();
        }
    }

The error triggers just in $ detail-> save ();
In the previous code you see that I try to print the object that is called $ det and the $ detail object and it shows me in console the following impression:

    pruebaArray↵(↵    [idproducto] => 24↵    [producto] => Yoke Nuevo2↵   
 [cantidad] => 2↵    [precio] => 2400.00↵    [stock] => 970↵)↵pruebaimpresion
 detalleApp\DetallePedido Object↵(↵    [table:protected] => detalle_pedidos↵ 
   [fillable:protected] => Array↵        (↵            [0] => idventa↵       
     [1] => idproducto↵            [2] => cantidad↵            [3] => precio↵
        )↵↵    [timestamps] => ↵    [connection:protected] => ↵    
[primaryKey:protected] => id↵    [keyType:protected] => int↵    [incrementing]
 => 1↵    [with:protected] => Array↵        (↵        )↵↵    
[withCount:protected] => Array↵        (↵        )↵↵    [perPage:protected] =>
 15↵    [exists] => ↵    [wasRecentlyCreated] => ↵    [attributes:protected] =>
 Array↵        (↵            [idpedido] => 10↵            [idproducto] => 24↵  
          [cantidad] => 2↵            [precio] => 2400.00↵        )↵↵    
[original:protected] => Array↵        (↵        )↵↵    [changes:protected] =>
 Array↵        (↵        )↵↵    [casts:protected] => Array↵        (↵        )↵↵
    [dates:protected] => Array↵        (↵        )↵↵    [dateFormat:protected] 
=> ↵    [appends:protected] => Array↵        (↵        )↵↵    
[dispatchesEvents:protected] => Array↵        (↵        )↵↵   
 [observables:protected] => Array↵        (↵        )↵↵    [relations:protected]
 => Array↵        (↵        )↵↵    [touches:protected] => Array↵        (↵      
  )↵↵    [hidden:protected] => Array↵        (↵        )↵↵    
[visible:protected] => Array↵        (↵        )↵↵    [guarded:protected] =>
 Array↵        (↵            [0] => *↵        )↵↵)↵impresion detalle{↵   
 "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'stock' in
 'field list' (SQL: insert into 'detalle_pedidos' ('idpedido', 'idproducto', 
'cantidad', 'precio') values (10, 24, 2, 2400.00))"

Where do I send the objects to the controller? I send them from a code of times registerOrder:

registrarPedido(){
                if (this.validarPedido()){
                    return;
                }

                let me = this;

                axios.post('/pedido/registrar',{
                    'idcliente': this.idcliente,
                    'tipo_comprobante': this.tipo_comprobante,
                    'serie_comprobante' : this.serie_comprobante,
                    'num_comprobante' : this.num_comprobante,
                    'impuesto' : this.impuesto,
                    'total' : this.total,
                    'data': this.arrayDetalle

                }).then(function (response) {
                    me.listado=1;
                    me.listarPedido(1,'','num_comprobante');
                    me.idcliente=0;
                    me.tipo_comprobante='Factura';
                    me.serie_comprobante='';
                    me.num_comprobante='';
                    me.impuesto=0.12;
                    me.total=0.0;
                    me.idproducto=0;
                    me.producto='';
                    me.cantidad=0;
                    me.precio=0;
                    me.arrayDetalle=[];

                }).catch(function (error) {
                    console.log(error.response);
                });
            }

I already cleaned the laravel cache and I do not get the error. Try adding the stock column in the database table and it did not work either.

    
asked by Angelica rueda 03.10.2018 в 21:05
source

0 answers