This system allows admins to create subscriptions with multiple features, users to purchase subscriptions and select desired features, and only enable purchased features for their shops.
- subscription_features - Stores feature definitions (HRM, Accounting, Return, Expense, etc.)
- subscription_feature - Pivot table linking subscriptions to features with pricing
- shop_subscription_features - Tracks which features a shop has purchased
add_selected_features_to_subscription_requests_table- Stores user's feature selections
$feature->subscriptions() // Many-to-many with Subscription
$feature->shopSubscriptions() // Many-to-many with ShopSubscription$subscription->features() // Features included in this subscription with prices$shopSubscription->features() // Features purchased by this shop- Navigate to Settings > Subscriptions
- The form now includes a "Features" section at the bottom
When creating or editing a subscription, you can:
- Check the features you want to include (HRM, Accounting, Return, Expense, etc.)
- Set individual pricing for each feature (in tk)
- Example:
- HRM = 100 tk
- Accounting = 75 tk
- Return = 50 tk
- Expense = 50 tk
The system will automatically link the selected features with their prices to the subscription.
- Go to Subscriptions > Purchase Subscription
- View all active subscriptions
- Click on a subscription to purchase
- You'll see all features included with their individual prices:
[ ] HRM ৳100 [ ] Accounting ৳75 [ ] Return ৳50 [ ] Expense ৳50 - Check the features you want to purchase
- Total Price updates automatically based on your selections
- Select from available payment gateways (Stripe, Razorpay, PayStack, PayPal, PayFast, Orange Money)
- Proceed to payment
- Payment is processed
- Selected features are automatically enabled for your shop
- Features are linked with expiration date matching subscription expiry
Controllers can use the FeatureAccessTrait to check features:
use App\Traits\FeatureAccessTrait;
class YourController extends Controller {
use FeatureAccessTrait;
public function someAction() {
// Check if feature is enabled
if (!$this->isFeatureEnabled('hrm')) {
// Feature not available
}
// Get all enabled features
$features = $this->getEnabledFeatures();
// Require a feature (throws 403 if not available)
$this->requireFeature('accounting');
}
}use App\Repositories\SubscriptionFeatureRepository;
// Check if feature is enabled for a shop
$isEnabled = SubscriptionFeatureRepository::isFeatureEnabledForShop($shop, 'hrm');
// Get enabled features for a shop
$features = SubscriptionFeatureRepository::getEnabledFeaturesForShop($shop);To show/hide menu items based on purchased features, update the sidebar.blade.php:
@if (auth()->user()->shop && $shop->currentSubscriptions()?->features->contains('slug', 'hrm'))
<!-- Show HRM Menu Items -->
@endif
@if (auth()->user()->shop && $shop->currentSubscriptions()?->features->contains('slug', 'accounting'))
<!-- Show Accounting Menu Items -->
@endifThe system includes 4 default features (seeded automatically):
hrm- Human Resource Managementaccounting- Accounting Modulereturn- Return Managementexpense- Expense Management
To add new features, either:
- Use the SubscriptionFeatureSeeder for default features
- Manually create them in the subscription_features table
- Create a new migration if needed
1. Admin creates Subscription
↓
2. Admin selects Features + Prices for that subscription
↓
3. User purchases subscription
↓
4. User selects which features to purchase
↓
5. Payment is processed with selected features
↓
6. ShopSubscription is created with expiration date
↓
7. Selected features are attached to ShopSubscription
↓
8. Menu items & features become available to the user
Run the SubscriptionFeatureSeeder to create default features:
php artisan db:seed --class=SubscriptionFeatureSeederOr in tinker:
Artisan::call('db:seed', ['--class' => 'SubscriptionFeatureSeeder']);-
Controllers:
app/Http/Controllers/SuperAdmin/SubscriptionController.php- Added feature handlingapp/Http/Controllers/SuperAdmin/PaymentGatewayController.php- Store selected featuresapp/Http/Controllers/SubscriptionPurchaseController.php- Pass features to view
-
Models:
app/Models/Subscription.php- Added relationshipsapp/Models/ShopSubscription.php- Added relationshipsapp/Models/SubscriptionFeature.php- New modelapp/Models/SubscriptionRequest.php- Added selected_features cast
-
Repositories:
app/Repositories/SubscriptionFeatureRepository.php- New repositoryapp/Repositories/SubscriptionRequestRepository.php- Updatedapp/Repositories/ShopSubscriptionRepository.php- May need updates for feature sync
-
Views:
resources/views/subscription/index.blade.php- Added features sectionresources/views/subscriptionPurchase/payment.blade.php- Added feature selection with dynamic pricing
-
Traits:
app/Traits/FeatureAccessTrait.php- New trait for feature checking
-
Migrations:
2024_04_01_000001_create_subscription_features_table.php2024_04_01_000002_create_subscription_feature_pivot_table.php2024_04_01_000003_create_shop_subscription_features_table.php2024_04_01_000004_add_selected_features_to_subscription_requests_table.php
-
Run migrations:
php artisan migrate
-
Seed default features:
php artisan db:seed --class=SubscriptionFeatureSeeder
-
Create subscriptions with features in admin panel
-
Update sidebar/controllers to check feature availability using FeatureAccessTrait
-
Test purchasing a subscription with different feature combinations
- Create subscription with multiple features and pricing
- View subscription in purchase page with correct feature list
- Select some features and verify total price updates dynamically
- Complete payment with selected features
- Verify shop_subscription_features table has entries
- Check that only purchased features are enabled
- Test feature access restrictions in controllers