app/Http/Controllers/SubCategoryController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\SubCategory  $subCategory
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, SubCategory $subcategory)
    {
        if (!empty($category->image)) {
            File::delete(asset('images/subcategory/' . $category->image));
        }
        $image = '';
        $updateData = $request->all();
        if ($request->hasFile('image')) {
            $image = time() . '.' . request()->image->getClientOriginalExtension();
            request()->image->move(public_path('images/category/'), $image);
            $updateData['image'] = $image;
        }
        if($subcategory->update($updateData)){
            return redirect()->route('subcategory.index')->with('success','Sub Category updated successfully');
        }
        return redirect()->back()->with('failed','Some error occured! rty again');
    }
public function update ( Request $ request , SubCategory $ subcategory ) { if ( ! empty ( $ category -> image ) ) { File :: delete ( asset ( 'images/subcategory/' . $ category -> image ) ) ; } $ image = '' ; $ updateData = $ request -> all ( ) ; if ( $ request -> hasFile ( 'image' ) ) { $ image = time ( ) . '.' . request ( ) -> image -> getClientOriginalExtension ( ) ; request ( ) -> image -> move ( public_path ( 'images/category/' ) , $ image ) ; $ updateData [ 'image' ] = $ image ; } if ( $ subcategory -> update ( $ updateData ) ) { return redirect ( ) -> route ( 'subcategory.index' ) -> with ( 'success' , 'Sub Category updated successfully' ) ; } return redirect ( ) -> back ( ) -> with ( 'failed' , 'Some error occured! rty again' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//