This module is a full Laravel refactor of a legacy Yii2 subscription slice. The goal was to rebuild the module using clean Laravel architecture, proper authorization, a complete trial system, performance fixes, and automated workflows — all supported with a full test suite.
- Business logic moved out of controllers
- Models contain only entity logic
- Policies handle all authorization
- Commands and Jobs manage automation
- Blade views contain zero business logic
- 7-day trial automatically created
- Expired trials automatically converted to paid
- Email notification dispatched through a queued Job
The original code suffered from N+1 queries.
The fix uses eager loading:
Subscription::with(['user', 'plan'])This reduces the query count to:
- 1 query for subscriptions
- 1 query for users
- 1 query for plans
Authorization is handled via SubscriptionPolicy:
- Admins → full access
- Users → can only view/cancel their own subscriptions
Controllers enforce this using:
$this->authorize('view', $subscription);and:
$this->authorize('cancel', $subscription);php artisan subscriptions:convert-trials
- Detects expired trials
- Converts them into paid subscriptions
- Dispatches a queue job for email notification
- Queue-driven
- Sends a
SubscriptionEmailmailable - Fully isolated from controller logic
Covers:
- Trial conversion logic
- Queue job dispatching
- Authorization access rules
- Model helpers & scopes
- Email sending behavior
- Feature-level endpoint access
All tests pass:
OK (10 tests, 30 assertions)

src/Models
src/Policies
src/Jobs
src/Providers
src/Http/Controllers
database/migrations
database/factories
database/seeders
tests/Feature
tests/Unit
resources/views
- Install dependencies
- Run migrations
- Seed database (optional)
- Start local server
- Run queue worker for emails
The module now provides:
- Clean and maintainable architecture
- Strong authorization boundaries
- Fully automated trial lifecycle
- Optimized database queries (N+1 fixed)
- Safe, idempotent migrations
- Queue-based notifications
- Full test coverage
A complete upgrade over the original Yii2 version, rebuilt using modern Laravel practices.
