Rinzler21
Rinzler21

Reputation: 476

Trying to update an element of an array delete the element instead of actualize it

* I have a sentence in my index function() that send a new value to the atribute of my database but when i do it the sentence eliminates the element with the id that i pass to the index instead of update it*

index function()

public function index(Request $request,$id_entrada,$id_venta_entrada,$id_costo,$correo)
    {   
        $detalle_entrada=new Detalle_venta_entrada();
        $detalle_entrada->precio=$id_costo;
        $detalle_entrada->fk_venta_entrada=$id_venta_entrada;
        $detalle_entrada->fk_entrada=$id_entrada;
        $detalle_entrada->save();
        $ventas=new Venta();
        $ventas->monto_total=$id_costo;
        $now = new \DateTime();
        $ventas->fecha_venta=$now->format('d-m-Y');
        $ventas->fk_cliente_natural=1;
        $sub = DB::select(DB::raw("SELECT precio_entrada from entrada WHERE id_entrada='$id_entrada'"));
        $subtotal = $sub[0]->precio_entrada;
        $monto = DB::select(DB::raw("SELECT precio from detalle_venta_entrada WHERE fk_venta_entrada='$id_venta_entrada'"));
        $monto_total = $monto[0]->precio;
        $ventas->save();
        $id = DB::select(DB::raw("SELECT Max(id_venta) as venta_id from venta"));
        $id_venta = $id[0]->venta_id;
        Entrada::where(['id_entrada'=>$id_entrada])->update(array(
            'disponible'=>'true'
        ));
        $detalle_venta_entrada = DB::select(DB::raw("SELECT id_detalle_entrada,precio,
                                                    (select numero_entrada from entrada where id_entrada='$id_entrada'),
                                                    (select fecha from venta_entrada where id_venta_entrada='$id_venta_entrada'),
                                                    (select monto_total from venta_entrada where id_venta_entrada='$id_venta_entrada' and fk_cliente_natural=1),
                                                    (select primer_nombre from cliente_natural where id_cliente_natural=1)
                                                    FROM detalle_venta_entrada WHERE fk_venta_entrada='$id_venta_entrada'and fk_entrada='$id_entrada'"));
        return view ('home.misOrdenes')->with('detalle_venta_entrada',$detalle_venta_entrada)
                                       ->with('id_entrada',$id_entrada)
                                       ->with('id_venta_entrada',$id_venta_entrada)
                                       ->with('detalle_entrada',$detalle_entrada)
                                       ->with('subtotal',$subtotal)
                                       ->with('monto_total',$monto_total)
                                       ->with('id_venta',$id_venta)
                                       ->with('correo',$correo);
    }

* sentence that give me the problem*

Entrada::where(['id_entrada'=>$id_entrada])->update(array(
            'disponible'=>'true'
        ));

Upvotes: 1

Views: 45

Answers (1)

Amit Sharma
Amit Sharma

Reputation: 1795

you can change it to. I don't think there needs to be array

Entrada::where('id_entrada'=>$id_entrada)->update(array(
        'disponible'=>'true'
    ));

Upvotes: 1

Related Questions