Refactoring to Action Classes in Laravel
Learn how to use Action Classes to implement the Single Responsibility Principle and clean up your Controllers and Services.
8 posts
Learn how to use Action Classes to implement the Single Responsibility Principle and clean up your Controllers and Services.
When a Model has too many states (Pending, Paid, Shipped...), code gets flooded with if/else. The State Pattern helps encapsulate state transition logic elegantly.
Stop repeating collection logic. Learn how to extend Laravel Collections with Macros, Mixins, and how to test them effectively for cleaner code.
Implement a robust payment system supporting Stripe, PayPal, and others using the Strategy Design Pattern. Learn to switch gateways dynamically without messy if-else statements.
Refactor complex business logic into maintainable, distinct steps using Laravel's Pipeline utility. Perfect for checkouts, data processing, and workflow management.
Refactor your data mapping logic by leveraging PHP 8 Attributes to declaratively map Markdown frontmatter to DTO properties.
Leveraging PHP 8.1+ Enums to clean up your Laravel models, validation logic, and database interactions.
Is your controller method 100 lines long? Here are 5 proven strategies to clean it up and make your code reusable and testable.