Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Actions Laravel Package

lorisleiva/laravel-actions

Laravel Actions organizes your app around single-purpose “action” classes. Write the core logic once in handle(), then run it as a controller, job, listener, command, or plain object. Keep business logic reusable, testable, and consistent across entry points.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Paradigm Shift: The package introduces a task-centric architecture (actions) instead of Laravel’s traditional controller/job/listener separation. This aligns well with Domain-Driven Design (DDD) and Clean Architecture, where business logic is encapsulated in reusable, single-purpose units.
  • Decoupling: Actions decouple logic from HTTP/queue/event layers, enabling better testability (e.g., PublishANewArticle::run()) and reusability across multiple contexts (e.g., CLI, API, events).
  • Laravel Ecosystem Compatibility: Seamlessly integrates with Laravel’s existing components (controllers, jobs, listeners, commands) via decorators, reducing boilerplate while maintaining familiarity.

Integration Feasibility

  • Low Friction: Replaces existing controllers/jobs with minimal refactoring (e.g., php artisan make:action generates a scaffold with asController, asJob, etc.).
  • Backward Compatibility: Supports Laravel 11–13 (as of v2.10.0) and PHP 8.2+. Migration path is straightforward for greenfield projects; legacy systems may require incremental adoption.
  • Tooling Support: Works with Laravel’s IDE helpers, Octane (via asListener), and testing frameworks (e.g., PestPHP’s make:action stubs).

Technical Risk

  • Breaking Changes: Dropped Laravel 10 support in v2.10.0; ensure alignment with your Laravel version.
  • Overhead for Simple Apps: May introduce unnecessary complexity for projects with trivial logic (e.g., CRUD apps). Mitigation: Use selectively for non-trivial business logic.
  • Testing Impact: Requires updating tests to leverage action-specific assertions (e.g., assertActionRuns()). Mitigation: Leverage the package’s built-in test helpers.
  • Performance: Minimal runtime overhead (decorators add ~1–2ms per action), but job/listener actions may introduce slight serialization costs. Mitigation: Benchmark critical paths.

Key Questions

  1. Adoption Strategy:
    • Should we big-bang migrate all controllers to actions, or pilot in a single module (e.g., "Orders")?
    • How will we handle legacy middleware tied to controllers (e.g., auth, throttle)?
  2. Testing:
    • Will we use the package’s test helpers (e.g., assertActionRuns()), or build custom assertions?
    • How will we mock actions in feature tests vs. unit tests?
  3. Team Buy-in:
    • Does the team prefer explicit controllers (current) or implicit actions (new) for readability?
    • Will developers adopt the make:action command over make:controller?
  4. Monitoring:
    • How will we track action execution time, failure rates, and contextual data (e.g., input params)?
  5. Long-Term Maintenance:
    • Will we customize decorators (e.g., JobDecorator) for project-specific needs?
    • How will we handle action versioning if business logic evolves?

Integration Approach

Stack Fit

  • Laravel Core: Native integration with controllers, jobs, listeners, and commands. No conflicts with Laravel’s service container or routing.
  • PHP 8.2+: Leverages modern features (e.g., named arguments, enums) for cleaner syntax.
  • Testing: Compatible with PestPHP, PHPUnit, and Laravel’s testing helpers (e.g., actingAs).
  • Dev Tools: Works with Laravel Forge, Vapor, and Octane (via asListener for event-driven workflows).

Migration Path

Phase Steps Risks Mitigation
Assessment Audit 10% of controllers for action suitability (e.g., complex logic). Underestimation of effort. Start with non-critical modules.
Pilot Replace 1–2 controllers with actions in a sandbox environment. Team resistance to change. Demonstrate reduced boilerplate.
Incremental Migrate modules by feature (e.g., "Payments" → "Invoices"). Broken dependencies. Use feature flags for gradual rollout.
Full Adoption Replace all controllers/jobs with actions. Testing debt. Automate test generation for actions.

Compatibility

  • Laravel Versions: Confirmed support for 11–13 (as of v2.10.0). Laravel 10 requires v2.9.x.
  • Third-Party Packages:
    • Inertia.js: Tested in v2.7.3 (reverted breaking change).
    • API Resources: Works via asController (e.g., return new ArticleResource($article)).
    • Validation: Supports FormRequest via validate() helper in actions.
  • Customization:
    • Extend decorators (e.g., JobDecorator) for project-specific needs.
    • Override make:action stubs to enforce team conventions (e.g., naming, docblocks).

Sequencing

  1. Infrastructure:
    • Update composer.json and run composer require lorisleiva/laravel-actions.
    • Publish config (if customizing decorators): php artisan vendor:publish --tag="actions-config".
  2. Development:
    • Train team on make:action vs. make:controller.
    • Refactor one module end-to-end (e.g., "User Onboarding").
  3. Testing:
    • Update test suites to use action-specific assertions.
    • Add integration tests for cross-context actions (e.g., asJob + asListener).
  4. Deployment:
    • Monitor action execution metrics (e.g., duration, failures).
    • Roll back if error rates exceed baseline.

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Eliminates repetitive controller/job scaffolding.
    • Centralized Logic: Business rules live in actions, not scattered across layers.
    • Easier Refactoring: Changing logic in handle() updates all contexts (HTTP, queue, event).
  • Cons:
    • New Abstraction Layer: Decorators may obscure debugging (e.g., stack traces).
    • Tooling Gaps: Limited IDE support for action-specific navigation (e.g., "Find usages").
  • Mitigation:
    • Document action input/output contracts (e.g., PHPDoc, OpenAPI).
    • Use custom decorators to add logging/metrics (e.g., LoggableActionDecorator).

Support

  • Debugging:
    • Action Context: Log $this->context() to inspect runtime data (e.g., request, event).
    • Decorators: Override handle() in custom decorators to add telemetry.
  • Error Handling:
    • Centralize exceptions in handle() (e.g., throw new ActionFailed($e)).
    • Use jobFailed(Throwable $e) for async actions to notify support systems.
  • Team Onboarding:
    • Workshop: Hands-on session on action creation, testing, and debugging.
    • Cheat Sheet: Quick reference for asController, asJob, etc.

Scaling

  • Performance:
    • Async Actions: Use asJob for long-running tasks (e.g., PDF generation).
    • Caching: Cache action results if idempotent (e.g., PublishANewArticle::run()).
  • Concurrency:
    • Job Actions: Leverage Laravel’s queue workers (e.g., Redis, database).
    • Listener Actions: Use shouldQueue() for event-driven scaling.
  • Monitoring:
    • Track action execution time (e.g., via action:executed Laravel event).
    • Alert on failed actions (e.g., Slack notification for ActionFailed events).

Failure Modes

Failure Type Impact Mitigation
Action Logic Error Breaks all contexts (HTTP, queue). Unit test handle() with edge cases.
Decorator Bug Fails silently (e.g., asJob). Custom decorators with validation.
Dependency Failure External API call in handle(). Retry logic (e.g., spatie/laravel-retryable).
Testing Gaps Untested action paths. Mandate test coverage for new actions.
Version Mismatch Package/Laravel compatibility. Pin versions in composer.json.

Ramp-Up

  • Training:
    • Video Tutorial: Walkthrough of action creation, testing, and deployment.
    • **Pair
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata