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 Actions Laravel Package

lorisleiva/laravel-actions

Unify your Laravel app logic into single-purpose “Action” classes that can run as controllers, jobs, listeners, or commands. Keep business logic in one place, reduce duplication, and generate actions via artisan with flexible asX entrypoints.

View on GitHub
Deep Wiki
Context7

⚡️ Laravel components that take care of one specific task

Frequently asked questions about Laravel Actions
How do I migrate from traditional Laravel controllers to actions without breaking existing routes?
Actions can coexist with controllers during migration. Use the `asController()` method in your action class to map it to existing routes. For gradual adoption, start by converting complex business logic into actions while keeping simple routes as controllers. The package provides no breaking changes, so you can refactor incrementally.
Can I use Laravel Actions with Laravel 13 and PHP 8.2+?
Yes, Laravel Actions officially supports Laravel 11–13 and PHP 8.1+. While PHP 8.2+ features like readonly properties or new attributes aren’t explicitly required, the package leverages modern PHP features like named arguments and type hints. Always check the latest release notes for compatibility updates.
How do I test an action that’s used as a controller or job?
Actions encourage unit testing via the `handle()` method. For HTTP paths, use Laravel’s built-in testing tools (e.g., `actingAs()` for auth). For jobs, queue them and assert results with `assertQueued()`. The package includes `Action::fake()` for mocking actions in tests, but ensure you mock dependencies passed to `handle()` explicitly.
Will using actions slow down my Laravel application?
No, actions introduce minimal runtime overhead—they’re thin wrappers around existing Laravel components. Performance impact is negligible unless you instantiate actions in tight loops (e.g., 1000+ times). For high-frequency use, call actions statically via `Action::run()` or cache expensive operations outside the action.
How do I handle validation in actions? Should I use FormRequests?
You can integrate FormRequests with actions by passing the validated data to `handle()`. For example, in `asController()`, validate the request first, then pass the validated array to `handle()`. Alternatively, use Laravel’s built-in validation directly in `handle()` for simpler cases. Actions don’t enforce FormRequests but support them seamlessly.
Can I use actions with Laravel Vapor or Octane for async processing?
Yes, actions work with Vapor and Octane. Use the `asJob()` method to queue actions asynchronously. For Octane, actions can leverage Laravel’s async workers natively. Ensure your action’s `handle()` method is stateless or uses dependency injection to avoid memory leaks in high-concurrency environments.
How do I handle errors or exceptions thrown in an action’s `handle()` method?
Exceptions in `handle()` propagate like normal Laravel exceptions. For HTTP actions (`asController`), they’re caught by Laravel’s exception handler. For jobs/listeners, use Laravel’s queue failure callbacks. You can also implement custom error handling in `asX()` methods (e.g., return a JSON response for API actions).
Are there alternatives to Laravel Actions for organizing business logic?
Alternatives include Laravel’s native controllers/jobs, packages like Spatie’s Laravel-Permission for role-based logic, or domain-specific solutions like Domain-Driven Design (DDD) repositories/services. However, Actions uniquely combine single-responsibility principles with Laravel’s ecosystem, reducing boilerplate for validation, middleware, and async workflows.
How do I structure actions for large-scale applications with many dependencies?
Use dependency injection in `handle()` to pass required services (e.g., repositories, APIs). For complex dependencies, define them in the action’s constructor. Group related actions in namespaces (e.g., `App/Actions/Articles`) and use Laravel’s service container for shared dependencies. Avoid global state to ensure testability and reusability.
Does Laravel Actions support middleware like traditional controllers?
Yes, actions inherit middleware from their associated routes when used as controllers (`asController()`). For jobs/listeners, middleware isn’t applicable, but you can add pre/post-processing logic in `asJob()` or `asListener()`. Complex middleware (e.g., auth, rate-limiting) must be explicitly configured in the action’s `asX()` methods.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope