Plugins
Coupons
A flexible coupon management system with customizable strategies and usage tracking.
Panel Builder
Dark theme support
Yes
Multi language support
Yes
Compatible with the latest version
Supported versions: 3.x
Documentation

Header

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A flexible coupon management system for Filament 3.x with customizable strategies and usage tracking.

#Installation

composer require noxoua/filament-coupons
 
php artisan filament-coupons:install

#Setup

Add the plugin to your Filament panel:

use Noxo\FilamentCoupons\CouponsPlugin;
 
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
CouponsPlugin::make(),
]);
}

#Usage

#Creating Strategies

Create custom coupon strategies:

php artisan make:coupons-strategy FreeSubscription

Register in config:

// config/filament-coupons.php
'strategies' => [
\App\Coupons\FreeSubscriptionStrategy::class,
],

#Strategy Example

class FreeSubscriptionStrategy extends CouponStrategy
{
public function schema(): array
{
return [
Forms\Components\TextInput::make('days')
->label('Days')
->numeric()
->required(),
];
}
 
public function apply(Coupon $coupon): bool
{
$user = auth()->user();
$days = $coupon->payload['days'] ?? 7;
 
// Your business logic
$user->extendSubscription($days);
 
// Configure notifications and redirects
$this->successNotification(
fn ($notification) => $notification
->title('Coupon Applied!')
->body("You got {$days} free days")
);
 
$this->successRedirectUrl('/dashboard');
 
// Consume coupon
return coupons()->consume($coupon, couponable: $user);
}
}

Available methods for strategies:

  • Custom notifications
    • successNotification
    • failureNotification
  • Custom redirects
    • successRedirectUrl
    • failureRedirectUrl

#Using the Action

The package provides a ready-to-use ApplyCouponAction that can be integrated anywhere in your Filament application:

In Livewire Components:

use Noxo\FilamentCoupons\Actions\ApplyCouponAction;
 
class Dashboard extends Component implements HasActions
{
use InteractsWithActions;
 
public function applyCouponAction(): Action
{
return ApplyCouponAction::make()
->button()
->label('Apply Coupon');
}
 
public function render()
{
return view('dashboard');
}
}
{{-- dashboard.blade.php --}}
<div>
<h2>Dashboard</h2>
{{ $this->applyCouponAction }}
</div>

In Resource Pages:

use Noxo\FilamentCoupons\Actions\ApplyCouponAction;
 
class ListPosts extends ListRecords
{
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
ApplyCouponAction::make(),
];
}
}

In Custom Pages:

use Noxo\FilamentCoupons\Actions\ApplyCouponAction;
 
class SettingsPage extends Page
{
protected function getHeaderActions(): array
{
return [
ApplyCouponAction::make()
->label('Redeem Coupon')
->color('success'),
];
}
}

#Manual Using

$coupon = Coupon::where('code', 'WELCOME2012')->first();
 
// Validate
if (coupons()->isValid($coupon)) {
// Apply
coupons()->applyCoupon($coupon);
}

#Testing

Run the test suite using:

composer test

The tests verify all aspects of coupon functionality, including strategy handling and integration with Filament. We recommend running tests after any changes.

#Credits

#License

The MIT License (MIT). Please see License File for more information.

Noxo

I'm a backend developer.

2
Plugins
55
Stars
More from this author
Featured Plugins