app/Http/Controllers/Admin/CouponsController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Coupon  $coupon
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Coupon $coupon)
    {
        if (Gate::denies('manage-cms')){
            return redirect()->route('admin.coupons.edit', $coupon);
        }
        $validator = Validator::make($request->all(), [
            'c_name'        => ['required', 'string'],
            'description'   => ['required', 'string'],
            'code'          => ['required', 'string'],
            'c_type'        => ['nullable', 'string'],
            'discount'      => ['nullable', 'string'],
            'date_start'    => ['nullable', 'date'],
            'date_end'      => ['nullable', 'date'],
            'uses_total'    => ['nullable', 'integer'],
            'uses_customer' => ['nullable', 'integer'],
            'status'        => ['nullable', 'integer'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.coupons.edit', $coupon);
        }
        $data = $request->all();
        $coupon->name = $data['c_name'];
        $coupon->description = $data['description'];
        $coupon->code = $data['code'];
        $coupon->type = $data['c_type'];
        $coupon->discount = $data['discount'];
        $coupon->date_start = $data['date_start'];
        $coupon->date_end = $data['date_end'];
        $coupon->uses_total = $data['uses_total'];
        $coupon->uses_customer = $data['uses_customer'];
        $coupon->status = $data['status'];
        if(!$coupon->save()) {
            $request->session()->flash('error', 'There is an error modifying the coupon!');
            return redirect()->route('admin.coupons.edit', $coupon);
        }
        $request->session()->flash('success', 'You have modified the coupon!');
        return redirect()->route('admin.coupons.index');
    }
public function update ( Request $ request , Coupon $ coupon ) { if ( Gate :: denies ( 'manage-cms' ) ) { return redirect ( ) -> route ( 'admin.coupons.edit' , $ coupon ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'c_name' => [ 'required' , 'string' ] , 'description' => [ 'required' , 'string' ] , 'code' => [ 'required' , 'string' ] , 'c_type' => [ 'nullable' , 'string' ] , 'discount' => [ 'nullable' , 'string' ] , 'date_start' => [ 'nullable' , 'date' ] , 'date_end' => [ 'nullable' , 'date' ] , 'uses_total' => [ 'nullable' , 'integer' ] , 'uses_customer' => [ 'nullable' , 'integer' ] , 'status' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.coupons.edit' , $ coupon ) ; } $ data = $ request -> all ( ) ; $ coupon -> name = $ data [ 'c_name' ] ; $ coupon -> description = $ data [ 'description' ] ; $ coupon -> code = $ data [ 'code' ] ; $ coupon -> type = $ data [ 'c_type' ] ; $ coupon -> discount = $ data [ 'discount' ] ; $ coupon -> date_start = $ data [ 'date_start' ] ; $ coupon -> date_end = $ data [ 'date_end' ] ; $ coupon -> uses_total = $ data [ 'uses_total' ] ; $ coupon -> uses_customer = $ data [ 'uses_customer' ] ; $ coupon -> status = $ data [ 'status' ] ; if ( ! $ coupon -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error modifying the coupon!' ) ; return redirect ( ) -> route ( 'admin.coupons.edit' , $ coupon ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have modified the coupon!' ) ; return redirect ( ) -> route ( 'admin.coupons.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .