app/Http/Controllers/Admin/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(Request $request, $id)
    {
        $rule=[
            'name' => 'required|string|min:2|max:50',
            'description' => 'required|string|min:2|max:255',
            'quantity'=> 'required',
            'extract' => 'required|string|min:2|max:255',
            'price' => 'required|numeric|between:0,9999999999.99',
            'foto' => 'image'
        ];
        $this->validate($request, $rule);
        $products=Product::findOrfail($id);
        $products->name=$request->input('name');
        $products->slug=str_slug($request->get('name'));
        $products->description=$request->input('description');
        $products->quantity=$request->get('quantity');
        $products->extract=$request->input('extract');
        $products->price=$request->input('price');
        $products->category_id=$request->get('category_id');
        Foto::create([
            'ruta' => $request -> foto-> store(''),
            'product_id' => $products->id,
        ]);
        if(!$product->isClean()){
            $products->save();
        }
         return redirect()->route('index-produ');
    }
public function update ( Request $ request , $ id ) { $ rule = [ 'name' => 'required|string|min:2|max:50' , 'description' => 'required|string|min:2|max:255' , 'quantity' => 'required' , 'extract' => 'required|string|min:2|max:255' , 'price' => 'required|numeric|between:0,9999999999.99' , 'foto' => 'image' ] ; $ this -> validate ( $ request , $ rule ) ; $ products = Product :: findOrfail ( $ id ) ; $ products -> name = $ request -> input ( 'name' ) ; $ products -> slug = str_slug ( $ request -> get ( 'name' ) ) ; $ products -> description = $ request -> input ( 'description' ) ; $ products -> quantity = $ request -> get ( 'quantity' ) ; $ products -> extract = $ request -> input ( 'extract' ) ; $ products -> price = $ request -> input ( 'price' ) ; $ products -> category_id = $ request -> get ( 'category_id' ) ; Foto :: create ( [ 'ruta' => $ request -> foto -> store ( '' ) , 'product_id' => $ products -> id , ] ) ; if ( ! $ product -> isClean ( ) ) { $ products -> save ( ) ; } return redirect ( ) -> route ( 'index-produ' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .