app/Http/Controllers/Admin/ProductsController.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)
    {
        $this->validate($request,
            [
            'title'=>'required|max:50',
            'price'=>'required',
            'description'=>'required|max:100'
            ,
            'imagePath'=>'required'
            ],[
            'required'=>'El campo :attribute es obligatorio'
            ]
            );
        $product=Product::find($id);
        $product->title  = $request->input('title');
        $product->price  = $request->input('price');
        $product->description  = $request->input('description');
        $nombreImagen = str_slug($product->title) . '.' .request()->imagePath->extension();
        request()->imagePath->storeAs('public', $nombreImagen);
        $product->imagePath = $nombreImagen;
        $product->save();
        return redirect()->action('Admin\ProductsController@index');
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'title' => 'required|max:50' , 'price' => 'required' , 'description' => 'required|max:100' , 'imagePath' => 'required' ] , [ 'required' => 'El campo :attribute es obligatorio' ] ) ; $ product = Product :: find ( $ id ) ; $ product -> title = $ request -> input ( 'title' ) ; $ product -> price = $ request -> input ( 'price' ) ; $ product -> description = $ request -> input ( 'description' ) ; $ nombreImagen = str_slug ( $ product -> title ) . '.' . request ( ) -> imagePath -> extension ( ) ; request ( ) -> imagePath -> storeAs ( 'public' , $ nombreImagen ) ; $ product -> imagePath = $ nombreImagen ; $ product -> save ( ) ; return redirect ( ) -> action ( 'Admin\ProductsController@index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// $product->imagePath  = $request->input('imagePath'); // storeAs recibe dos parametros el nombre de la carpeta y el nombre del archivo