app/Http/Controllers/Panel/PromotionsController.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)
    {
        $data = $this->validate($request,[
            'title' => 'required|string',
            'shipping' => 'nullable',
            'offer_percent' => 'nullable|numeric',
            'offer_time' => 'nullable',
            'description' => 'required',
            'image_promotion' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048'
        ],[
            'required' => 'Este campo es requerido.',
            'image_promotion.image' => 'Debe subir una imagen.',
            'image_promotion.mimes' => 'La imagen debe ser tipo :values.',
            'image_promotion.max' => 'La imagen no puede superar los :max kilobytes.'
        ]);
        $offer_time = getTimeOffer($data['offer_time']);
        $promotion = Promotion::find($id);
        $promotion->title = $data['title'];
        $promotion->shipping = $data['shipping'];
        $promotion->offer_percent = $data['offer_percent'];
        if (null != $offer_time) {
            $promotion->offer_from = $offer_time['offer_from'];
            $promotion->offer_to = $offer_time['offer_to'];
        }
        $promotion->description = \nl2br($data['description']);
        $promotion->save();
        $promotion->uploadFile($promotion, $request->image_promotion);
        return [
            'success' => true,
            'message' => 'Guardado exitosamente',
            'url' => route('promotions.index')
        ];
    }
public function update ( Request $ request , $ id ) { $ data = $ this -> validate ( $ request , [ 'title' => 'required|string' , 'shipping' => 'nullable' , 'offer_percent' => 'nullable|numeric' , 'offer_time' => 'nullable' , 'description' => 'required' , 'image_promotion' => 'nullable|image|mimes:jpg,png,jpeg,gif,svg|max:2048' ] , [ 'required' => 'Este campo es requerido.' , 'image_promotion.image' => 'Debe subir una imagen.' , 'image_promotion.mimes' => 'La imagen debe ser tipo :values.' , 'image_promotion.max' => 'La imagen no puede superar los :max kilobytes.' ] ) ; $ offer_time = getTimeOffer ( $ data [ 'offer_time' ] ) ; $ promotion = Promotion :: find ( $ id ) ; $ promotion -> title = $ data [ 'title' ] ; $ promotion -> shipping = $ data [ 'shipping' ] ; $ promotion -> offer_percent = $ data [ 'offer_percent' ] ; if ( null != $ offer_time ) { $ promotion -> offer_from = $ offer_time [ 'offer_from' ] ; $ promotion -> offer_to = $ offer_time [ 'offer_to' ] ; } $ promotion -> description = \ nl2br ( $ data [ 'description' ] ) ; $ promotion -> save ( ) ; $ promotion -> uploadFile ( $ promotion , $ request -> image_promotion ) ; return [ 'success' => true , 'message' => 'Guardado exitosamente' , 'url' => route ( 'promotions.index' ) ] ; }
Update the specified resource in storage.
Update the specified resource in storage .
# Validaciones # Converti el tiempo en unix # Modelo # Datos a guardar # Si existe el tiempo de oferta # Guardar # Subir imagen