app/Http/Controllers/ProductController.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(UpdateProductRequest $request, Product $product)
    {
        if ($request->validated()){
           $product->update([
               'title'=>$request->validated()['title'],
               'info'=>$request->validated()['info'],
               'description'=>$request->validated()['description'],
               'price'=>$request->validated()['price'],
               'image'=>$request->file('image')->store('public/thumbnails'),
               'user_id'=>auth()->user()->id,
           ]);
           foreach ($request->file('images') as $image){
               $product->Slides()->update([
                   'name'=>$image->store('public/slides')
               ]);
           }
            $product->Category()->sync($request->input('categories'));
            $product->tag()->sync($request->input('tags'));
           return redirect()->route('product.index')->with('message','Product Update is Done');
        }else{
            return redirect()->route('product.create')->withErrors($request->validated());
        }
    }
public function update ( UpdateProductRequest $ request , Product $ product ) { if ( $ request -> validated ( ) ) { $ product -> update ( [ 'title' => $ request -> validated ( ) [ 'title' ] , 'info' => $ request -> validated ( ) [ 'info' ] , 'description' => $ request -> validated ( ) [ 'description' ] , 'price' => $ request -> validated ( ) [ 'price' ] , 'image' => $ request -> file ( 'image' ) -> store ( 'public/thumbnails' ) , 'user_id' => auth ( ) -> user ( ) -> id , ] ) ; foreach ( $ request -> file ( 'images' ) as $ image ) { $ product -> Slides ( ) -> update ( [ 'name' => $ image -> store ( 'public/slides' ) ] ) ; } $ product -> Category ( ) -> sync ( $ request -> input ( 'categories' ) ) ; $ product -> tag ( ) -> sync ( $ request -> input ( 'tags' ) ) ; return redirect ( ) -> route ( 'product.index' ) -> with ( 'message' , 'Product Update is Done' ) ; } else { return redirect ( ) -> route ( 'product.create' ) -> withErrors ( $ request -> validated ( ) ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .
//