app/Http/Controllers/PenjualanController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $request->validate([
            'jumlah_barang'          =>  'required|numeric',
        ]);
        $detail_penjualan = DetailPenjualan::find($id);
        $barang = Barang::where('id', $detail_penjualan->barang_id)->first();
        $detail_penjualan->jumlah_barang = $request->jumlah_barang;
        $detail_penjualan->harga_jual = $barang->harga_jual * $request->jumlah_barang;
        $detail_penjualan->save();
        return redirect()->route('penjualan.index')->with('info', 'Data barang berhasil diupdate');
    }
public function update ( Request $ request , $ id ) { $ request -> validate ( [ 'jumlah_barang' => 'required|numeric' , ] ) ; $ detail_penjualan = DetailPenjualan :: find ( $ id ) ; $ barang = Barang :: where ( 'id' , $ detail_penjualan -> barang_id ) -> first ( ) ; $ detail_penjualan -> jumlah_barang = $ request -> jumlah_barang ; $ detail_penjualan -> harga_jual = $ barang -> harga_jual * $ request -> jumlah_barang ; $ detail_penjualan -> save ( ) ; return redirect ( ) -> route ( 'penjualan.index' ) -> with ( 'info' , 'Data barang berhasil diupdate' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .