Overview
Actions are reusable classes that encapsulate business logic. They follow the action pattern and can be invoked from controllers, commands, or other parts of your application.Creating an Action
Actions are typically located in thesrc/Actions directory. Here’s a basic structure:
Using Actions
Actions can be injected into your controllers or other classes:Best Practices
- Single Responsibility: Each action should do one thing well
- Dependency Injection: Use Laravel’s container for dependencies
- Easy Testing: Actions are straightforward to unit test
- Reusability: Use the same action from multiple places in your code
Action Types
Common action patterns in Unleash Commerce include:- Create actions
- Update actions
- Delete actions
- Custom business logic actions