app/Http/Controllers/ProductController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Product  $product
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request,$id)
    {   
       $editData=Product::find($id);
        $val=['pname' => 'required|max:15',
        'pdetail' => 'required|max:300',
        'pimage' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',];
        $this->validate($request,$val);
        $editData->name=$request->pname;
        $editData->detail=$request->pdetail;
        if ($image = $request->file('pimage')) {
            $file='storage/app/image/'.$editData->image;
            if(File::exists($file)){
                File::delete($file);
            }
            $dest_Path = 'storage/app/image/';
            $prod_image = date('YmdHis') . "." . $image->getClientOriginalExtension();
            $image->move($dest_Path, $prod_image);
            $editData->image = "$prod_image";
        }
        $editData->save();
        return redirect('/')
        ->with('success','Product updated successfully.');
    }
public function update ( Request $ request , $ id ) { $ editData = Product :: find ( $ id ) ; $ val = [ 'pname' => 'required|max:15' , 'pdetail' => 'required|max:300' , 'pimage' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048' , ] ; $ this -> validate ( $ request , $ val ) ; $ editData -> name = $ request -> pname ; $ editData -> detail = $ request -> pdetail ; if ( $ image = $ request -> file ( 'pimage' ) ) { $ file = 'storage/app/image/' . $ editData -> image ; if ( File :: exists ( $ file ) ) { File :: delete ( $ file ) ; } $ dest_Path = 'storage/app/image/' ; $ prod_image = date ( 'YmdHis' ) . " . " . $ image -> getClientOriginalExtension ( ) ; $ image -> move ( $ dest_Path , $ prod_image ) ; $ editData -> image = " $ prod_image " ; } $ editData -> save ( ) ; return redirect ( '/' ) -> with ( 'success' , 'Product updated successfully.' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .