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([
            'name' => 'required',
            'brand' => 'required',
            'price' => 'required',
        ]);
        if ($request->hasFile('image')) {
            $imageName = time().'.'.$request->image->getClientOriginalExtension();
            $request->image->move(public_path('/uploads/product'), $imageName);
            $request->image = $imageName;
        } 
        if ($request->image == null || $request->image == '') {
            unset($request['image']);
        }
        $product->update($request->all());
        return redirect()->route('products.index')
            ->with('success', 'Product updated successfully');
    }
public function update ( Request $ request , Product $ product ) { request ( ) -> validate ( [ 'name' => 'required' , 'brand' => 'required' , 'price' => 'required' , ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ imageName = time ( ) . '.' . $ request -> image -> getClientOriginalExtension ( ) ; $ request -> image -> move ( public_path ( '/uploads/product' ) , $ imageName ) ; $ request -> image = $ imageName ; } if ( $ request -> image == null || $ request -> image == '' ) { unset ( $ request [ 'image' ] ) ; } $ product -> update ( $ request -> all ( ) ) ; return redirect ( ) -> route ( 'products.index' ) -> with ( 'success' , 'Product updated successfully' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// 'detail' => 'required', // 'image' => ['required', 'file', 'mimes:jpeg,bmp,png'],