PHPackages                             ashadozzaman/coupon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ashadozzaman/coupon

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ashadozzaman/coupon
===================

This package generate coupon/discount for any kinds of course or product...

v1.0.1(3y ago)311MITBlade

Since Sep 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Ashadozzaman/larave-coupon)[ Packagist](https://packagist.org/packages/ashadozzaman/coupon)[ RSS](/packages/ashadozzaman-coupon/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Laravel Coupon 🎟

-----------------

[](#laravel-coupon-)

This package generate coupon/discount for any kinds of course or product selling website...🎟

[![Latest Version on Packagist](https://camo.githubusercontent.com/52b844e8800afd459dfcc54331d0e8ad7a9297374ed2290c2f1b5077f11a08a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61736861646f7a7a616d616e2f636f75706f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashadozzaman/coupon)[![Total Downloads](https://camo.githubusercontent.com/c5467735d742bb786e62fdb44daa2d0d7b43c62949feb3e4a06890770a81d9bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61736861646f7a7a616d616e2f636f75706f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashadozzaman/coupon)
Here is an example of how you can create coupon them:

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ashadozzaman/coupon
```

Now you should register CouponServiceProvider in config/app.php

```
'providers' => [
  Ashadozzaman\Coupon\CouponServiceProvider::class,
]
```

The package will automatically register itself.

You can publish the migration with below command, it's copy generate file config/coupon.php also crate folde views/vendor/coupon for create coupon, it you want you can change all file design. But don't cut form structure...

```
php artisan vendor:publish --provider="Ashadozzaman\Coupon\CouponServiceProvider"
```

config/coupon.php file show bellow. here you set you necessary information

```
 App\Models\Course::class,

    //this table/model use for specific category coupon generate, like Product/products, Course/courses
    'coupon_for_category_table' => App\Models\Category::class,

    //money symbol
    'money_symbol' => '৳',

    //is_admin middleware define here
    //'is_admin' => \App\Http\Middleware\IsAdmin::class, example default action this

    'IsAdmin' => 'is_admin',

];
```

After the migration has been published you can create the vouchers table by running the migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

The basic concept of this package is that you can create coupon by admin for specific course/product and course/product category. For access this feature you declure your admin authentication middleware in **config/coupon.php** file like bellow:-

```
return [
     --------
     --------
    'IsAdmin' => 'is_admin', //you should replace your middleware to is_admin thanks
]
```

Model Declare
-------------

[](#model-declare)

You must be declare your coupon related items models like products/coures and categories table model example show bellow:-

```
 App\Models\Course::class,

    //this table/model use for specific category coupon generate, like Product/products, Course/courses
    'coupon_for_category_table' => App\Models\Category::class,

]
```

After complete middleware register. Now you able to access create coupon in you admin section. Now you just call two route for creating coupon. Two route show bellow:-

```
Route name: route(coupon.index), Route Url: /coupon
Route name: route(coupon_category.index), Route Url: /coupon_category
//use example
Coupon
Coupon Category
```

Admin coupon create process done here
-------------------------------------

[](#admin-coupon-create-process-done-here)

Use Coupon In Frontend 🎟
------------------------

[](#use-coupon-in-frontend-)

Coupon use basically in your checkout page. So you just use coupon easily in checkout page with same route. Show example bellow code:-

route/web.php (It's only example, you write code in your own way)
-----------------------------------------------------------------

[](#routewebphp--its-only-example-you-write-code-in-your-own-way)

```
Route::match(array('GET', 'POST'), 'checkout/{id?}', [HomeController::class,'checkout_course'])->name('checkout.course');
```

Http/Controllers/HomeController.php (It's only example, you write code in your own way)
---------------------------------------------------------------------------------------

[](#httpcontrollershomecontrollerphp--its-only-example-you-write-code-in-your-own-way)

In controller must be use bellow Trait:-

```
use Ashadozzaman\Coupon\Http\Traits\CouponGenerate;
class HomeController extends Controller
{
    use CouponGenerate;
    --
    --
    --
 }
```

This function is work in my side. It's show for example perpose.

```
public function checkout_course(Request $request,$id = null){
    $data['course'] = Course::findOrFail($id);
    $course = Course::findOrFail($id);
    if($request->coupon){
        $coupon = $request->coupon;
        $item = $id;
        $item_category = $course->category->id;
        $customer_id = auth()->user->id; //user, student, customer //login user

        //must be call with 4 perameter 1.coupon 2. coupon item id(course) 3.item category id 4.Customer id
        $response = $this->checkCoupunStatus($coupon,$item,$item_category,$customer_id);
        if($response['status'] == "error"){
            Session::flash('message',$response['message']);
            return redirect()->back();
        }else{
            $data['coupon'] = $response;
        }

    }
    return view('checkout',$data);

}
```

Using this trait function check coupon status, for use coupon time. Must be pass necesary all perameter. This function return response in array. In array pass two type status 1. success 2. error.

```
//must be call with 4 perameter 1.coupon 2. coupon item id(course) 3.item category id 4.Customer id //login user
$response = $this->checkCoupunStatus($coupon,$item,$item_category,$customer_id);
```

Response example bellow show:-

```
//error
array:2 [▼
  "status" => "error"
  "message" => "This coupon is not vaild for this product"
]
//success
array:6 [▼
  "status" => "success"
  "price" => 65.0
  "final_price" => 55.0
  "rate" => 10
  "coupon" => "O4BY-TSKO"
  "type" => "৳"
]
```

checkout.blade.php (It's only example, you write code in your own way)
----------------------------------------------------------------------

[](#checkoutbladephp-its-only-example-you-write-code-in-your-own-way)

```

   Course
  @if (Session::has('message'))
      {{ Session::get('message') }}
  @endif

              @csrf
              Name : {{ $course->name }}

              Price : {{ $course->amount }}

              @if (isset($coupon))
                  Discount: - {{ $coupon['rate'] }} {{ $coupon['type'] }}
                  Final Price

                  Use Coupon

              @else
                  Final Price

              @endif
              Checkout

              @csrf
              Use Coupon

              Use Coupon

```

After use coupon, when you submit checkout form that's mean when you save checkout details. You must be call bellow trail function:-

```
//must be pass 2 perameter customer_id(login user id),coupon_code;
$response = $this->useCouponByUser($data['customer_id'],$request->coupon);
```

Using this function store coupon used user and coupon code. So must be call this after save checkout details. Bellow show details example:-

```
 public function checkout_submit(Request $request){
      $data['customer_id'] = auth()->user->id;//login user id
      $data['course_id'] = $request->course_id; // course/product
      $data['price'] = $request->price;
      $booking = Booking::create($data);
      if(isset($booking)){
          if($request->coupon){
              //must be pass 2 perameter customer_id(login user id),coupon_code;
              $response = $this->useCouponByUser($data['customer_id'],$request->coupon);
          }
      }
  }
```

Respone example show bellow:-

```
$data = [
    'status' => 'success',
    'message'  => 'Coupon use successfully',
];
```

Contributor
-----------

[](#contributor)

Ashadozzaman Shvou()

Support
=======

[](#support)

For any query please send email to

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

1332d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/601d7f673b468288d377d529a07dc6ab3b777a9a17bd1e4d6e289ff2f772099a?d=identicon)[Ashadozzaman](/maintainers/Ashadozzaman)

---

Top Contributors

[![Ashadozzaman](https://avatars.githubusercontent.com/u/49988527?v=4)](https://github.com/Ashadozzaman "Ashadozzaman (15 commits)")

### Embed Badge

![Health badge](/badges/ashadozzaman-coupon/health.svg)

```
[![Health](https://phpackages.com/badges/ashadozzaman-coupon/health.svg)](https://phpackages.com/packages/ashadozzaman-coupon)
```

###  Alternatives

[mediawiki/semantic-cite

A Semantic MediaWiki extension to manage citation resources.

2310.2k1](/packages/mediawiki-semantic-cite)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
