app/Http/Controllers/LaptopController.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)
    {
        if(empty($request->file('image'))){
            $laptop = laptop::findOrFail($id);
            $laptop -> update([
                'name' => $request->name,
                'price' => $request->price
            ]);
            return redirect()->route('laptop.index') ->with('success', 'Data berhasil diedit');
        }
        else{
            $laptop = laptop::findOrFail($id);
            Storage::delete($laptop->image);
            $laptop -> update([
                'name' => $request->name,
                'price' => $request->price,
                'image'=>$request->file('image')->store('laptop-image')
            ]);
            return redirect()->route('laptop.index') ->with('success', 'Data berhasil diedit');
        }
    }
public function update ( Request $ request , $ id ) { if ( empty ( $ request -> file ( 'image' ) ) ) { $ laptop = laptop :: findOrFail ( $ id ) ; $ laptop -> update ( [ 'name' => $ request -> name , 'price' => $ request -> price ] ) ; return redirect ( ) -> route ( 'laptop.index' ) -> with ( 'success' , 'Data berhasil diedit' ) ; } else { $ laptop = laptop :: findOrFail ( $ id ) ; Storage :: delete ( $ laptop -> image ) ; $ laptop -> update ( [ 'name' => $ request -> name , 'price' => $ request -> price , 'image' => $ request -> file ( 'image' ) -> store ( 'laptop-image' ) ] ) ; return redirect ( ) -> route ( 'laptop.index' ) -> with ( 'success' , 'Data berhasil diedit' ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .