app/Http/Controllers/ProductController.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)
    {
        Product::where('id',$id)->update([
            'product_name'=>$request->nama_produk,
            'price'=>$request->harga_produk,
            'description'=>$request->deskripsi_produk,
            'stock'=>$request->stok_produk,
            'weight'=>$request->berat_produk,
            'updated_at'=>Carbon::now()->format('Y-m-d H:i:s')
        ]);
        ProductCategoryDetails::where ('product_id', $id)->delete();
        foreach ($request->kategori as $row){
            $productCategoryDetail = new ProductCategoryDetails;
            $productCategoryDetail->product_id = $id;
            $productCategoryDetail->category_id = $row;
            $productCategoryDetail->created_at = Carbon::now()->format('Y-m-d H:i:s');
            $productCategoryDetail->updated_at = Carbon::now()->format('Y-m-d H:i:s');
            $productCategoryDetail->save();
        }
        return redirect('/product/'.$id)->with('berhasil','Data produk berhasil diupdate!');
    }
public function update ( Request $ request , $ id ) { Product :: where ( 'id' , $ id ) -> update ( [ 'product_name' => $ request -> nama_produk , 'price' => $ request -> harga_produk , 'description' => $ request -> deskripsi_produk , 'stock' => $ request -> stok_produk , 'weight' => $ request -> berat_produk , 'updated_at' => Carbon :: now ( ) -> format ( 'Y-m-d H:i:s' ) ] ) ; ProductCategoryDetails :: where ( 'product_id' , $ id ) -> delete ( ) ; foreach ( $ request -> kategori as $ row ) { $ productCategoryDetail = new ProductCategoryDetails ; $ productCategoryDetail -> product_id = $ id ; $ productCategoryDetail -> category_id = $ row ; $ productCategoryDetail -> created_at = Carbon :: now ( ) -> format ( 'Y-m-d H:i:s' ) ; $ productCategoryDetail -> updated_at = Carbon :: now ( ) -> format ( 'Y-m-d H:i:s' ) ; $ productCategoryDetail -> save ( ) ; } return redirect ( '/product/' . $ id ) -> with ( 'berhasil' , 'Data produk berhasil diupdate!' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//Memperbarui data