app/Http/Controllers/ProductController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Product  $product
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Product $product)
    {
        $request->validate([
            'user_id' => 'required',
            'name' => 'required',
            'description' => 'required',
            'category_id' => 'required',
            'sub_category_id' => 'required',
            'photo' => 'required|mimes:png,jpg,jpeg'
        ]);
        $product->update($request->all());
        if ($request->file('photo')) {
            $request->file('photo')->store('public/products');
        }
        $product->photo = $request->photo->hashName();
        $product->save();
        return redirect()->route('products.index')
                        ->with('success','Product updated successfully');
    }
public function update ( Request $ request , Product $ product ) { $ request -> validate ( [ 'user_id' => 'required' , 'name' => 'required' , 'description' => 'required' , 'category_id' => 'required' , 'sub_category_id' => 'required' , 'photo' => 'required|mimes:png,jpg,jpeg' ] ) ; $ product -> update ( $ request -> all ( ) ) ; if ( $ request -> file ( 'photo' ) ) { $ request -> file ( 'photo' ) -> store ( 'public/products' ) ; } $ product -> photo = $ request -> photo -> hashName ( ) ; $ product -> save ( ) ; return redirect ( ) -> route ( 'products.index' ) -> with ( 'success' , 'Product updated successfully' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .