- How do I generate an Action class in Laravel using laraditz/action?
- Run `php artisan make:action [ActionName]` to generate a new Action class in the `app/Actions/` directory. The generated file includes a constructor and `handle()` method, ready for customization with your business logic.
- Can I use this package with Laravel 9, 10, 11, 12, or 13?
- Yes, laraditz/action supports Laravel 9 through 13. Ensure your project meets the PHP 8.2+ requirement for full compatibility. The package follows Laravel’s versioning closely for seamless integration.
- Does laraditz/action support dependency injection for services like Mailer or Repository?
- Absolutely. Type-hint services in the `handle()` method (e.g., `Mailer $mailer`), and Laravel’s service container will automatically inject them. This works the same way as controller method injection.
- How do I run an Action class statically vs. instantiating it manually?
- Use `ActionClass::run(arg1: value1)` for static execution, or instantiate first (`new ActionClass(arg1: value1)`) and call `->run()`. Both methods are equivalent and leverage constructor property promotion for clean syntax.
- Will this package work with Lumen, or is it Laravel-only?
- laraditz/action is fully compatible with Lumen. It leverages Laravel’s service container patterns, which Lumen also supports, making it ideal for lightweight APIs or microservices built on either framework.
- How do I test an Action class in isolation?
- Actions are designed for unit testing. Mock dependencies in your test’s `handle()` method or use Laravel’s service container bindings. Since actions are stateless, you can test them without controllers or middleware.
- Does this package handle validation or transactions automatically?
- No, laraditz/action is minimalist. For validation, manually use Laravel’s `FormRequest` or `Validator` in `handle()`. For transactions, wrap multi-step logic in `DB::transaction()` or use Laravel’s `QueuedClosure` for queued actions.
- Can I queue an Action class for delayed execution?
- Yes, implement Laravel’s `ShouldQueue` interface in your Action class. The package supports queuing out of the box, allowing you to dispatch actions to queues like `database`, `redis`, or `sync` for async processing.
- What’s the performance impact of using Actions vs. controllers?
- The performance impact is negligible for most use cases. Actions reduce boilerplate and improve readability without adding overhead. For high-frequency operations, the abstraction is minimal, but avoid overusing it for trivial logic.
- Are there alternatives to laraditz/action for Laravel actions?
- Yes, alternatives include `spatie/laravel-action` (more feature-rich, with validation and middleware support) or `laravel-ide-helper`-compatible packages like `orchid/console`. laraditz/action stands out for its simplicity and zero-config setup.