Coupons
A flexible coupon management system with customizable strategies and usage tracking.
Author:
Noxo
Documentation

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
successNotificationfailureNotification
- Custom redirects
successRedirectUrlfailureRedirectUrl
#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.
The author
From the same author
Featured Plugins
A selection of plugins curated by the Filament team
Custom Dashboards
Let your users build and share their own dashboards with a drag-and-drop interface. Define your data sources in PHP and let them do the rest.
Filament
Custom Fields
Eliminate custom field migrations forever. Let your users create and manage form fields directly in Filament admin panels with 20+ built-in field types, validation, and zero database changes.
Relaticle
Advanced Tables (formerly Filter Sets)
Supercharge your tables with powerful features like user-customizable views, quick filters, multi-column sorting, advanced table searching, convenient view management, and more. Compatible with Resource Panel Tables, Relation Managers, Table Widgets, and Table Builder!
Kenneth Sese