Discount vouchers and coupons management - create individual coupon or full campaign with a lot of coupons.

CRUDs created:

  • Campaigns
  • Coupons

Modules Coupon management

Click to see Demo video

Coupons Management Video

Example Generated Code - CouponsController.php

<?php

namespace App\Http\Controllers\Admin;

use App\Coupon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\StoreCouponsRequest;
use App\Http\Requests\Admin\UpdateCouponsRequest;

class CouponsController extends Controller
{
    /**
     * Display a listing of Coupon.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        if (! Gate::allows('coupon_access')) {
            return abort(401);
        }

        $coupons = Coupon::all();

        return view('admin.coupons.index', compact('coupons'));
    }

    /**
     * Show the form for creating new Coupon.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        if (! Gate::allows('coupon_create')) {
            return abort(401);
        }
        
        $campaigns = \App\CouponCampaign::get()->pluck('title', 'id')->prepend(trans('quickadmin.qa_please_select'), '');

        return view('admin.coupons.create', compact('campaigns'));
    }

    /**
     * Store a newly created Coupon in storage.
     *
     * @param  \App\Http\Requests\StoreCouponsRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function store(StoreCouponsRequest $request)
    {
        if (! Gate::allows('coupon_create')) {
            return abort(401);
        }
        $coupon = Coupon::create($request->all());



        return redirect()->route('admin.coupons.index');
    }


    /**
     * Show the form for editing Coupon.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        if (! Gate::allows('coupon_edit')) {
            return abort(401);
        }
        
        $campaigns = \App\CouponCampaign::get()->pluck('title', 'id')->prepend(trans('quickadmin.qa_please_select'), '');

        $coupon = Coupon::findOrFail($id);

        return view('admin.coupons.edit', compact('coupon', 'campaigns'));
    }

    /**
     * Update Coupon in storage.
     *
     * @param  \App\Http\Requests\UpdateCouponsRequest  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateCouponsRequest $request, $id)
    {
        if (! Gate::allows('coupon_edit')) {
            return abort(401);
        }
        $coupon = Coupon::findOrFail($id);
        $coupon->update($request->all());



        return redirect()->route('admin.coupons.index');
    }


    /**
     * Display Coupon.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        if (! Gate::allows('coupon_view')) {
            return abort(401);
        }
        $coupon = Coupon::findOrFail($id);

        return view('admin.coupons.show', compact('coupon'));
    }


    /**
     * Remove Coupon from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        if (! Gate::allows('coupon_delete')) {
            return abort(401);
        }
        $coupon = Coupon::findOrFail($id);
        $coupon->delete();

        return redirect()->route('admin.coupons.index');
    }

    /**
     * Delete all selected Coupon at once.
     *
     * @param Request $request
     */
    public function massDestroy(Request $request)
    {
        if (! Gate::allows('coupon_delete')) {
            return abort(401);
        }
        if ($request->input('ids')) {
            $entries = Coupon::whereIn('id', $request->input('ids'))->get();

            foreach ($entries as $entry) {
                $entry->delete();
            }
        }
    }

}