app/Http/Controllers/Admin/CouponsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        if (Gate::denies('manage-cms')){
            return redirect()->route('admin.coupons.create');
        }
        $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.create');
        }
        $data = $request->all();
        $coupon = Coupon::create([
            'name'          => $data['c_name'],
            'description'   => $data['description'],
            'code'          => $data['code'],
            'type'          => $data['c_type'],
            'discount'      => $data['discount'],
            'date_start'    => $data['date_start'],
            'date_end'      => $data['date_end'],
            'uses_total'    => $data['uses_total'],
            'uses_customer' => $data['uses_customer'],
            'status'        => $data['status'],
        ]);
        if($coupon == NULL) {
            $request->session()->flash('error', 'There is an error creating the coupon!');
            return redirect()->route('admin.coupons.create');
        }
        $request->session()->flash('success', 'You have created the coupon!');
        return redirect()->route('admin.coupons.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-cms' ) ) { return redirect ( ) -> route ( 'admin.coupons.create' ) ; } $ 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.create' ) ; } $ data = $ request -> all ( ) ; $ coupon = Coupon :: create ( [ 'name' => $ data [ 'c_name' ] , 'description' => $ data [ 'description' ] , 'code' => $ data [ 'code' ] , 'type' => $ data [ 'c_type' ] , 'discount' => $ data [ 'discount' ] , 'date_start' => $ data [ 'date_start' ] , 'date_end' => $ data [ 'date_end' ] , 'uses_total' => $ data [ 'uses_total' ] , 'uses_customer' => $ data [ 'uses_customer' ] , 'status' => $ data [ 'status' ] , ] ) ; if ( $ coupon == NULL ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error creating the coupon!' ) ; return redirect ( ) -> route ( 'admin.coupons.create' ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have created the coupon!' ) ; return redirect ( ) -> route ( 'admin.coupons.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .