Laravel Actions
Laravel Actions stats
- Downloads
- 2.2M
- Stars
- 2,201
- Open Issues
- 24
- Forks
- 111
Laravel components that take care of one specific task
Laravel Actions Package Summary
The Laravel Actions package offers a streamlined approach to structuring logic in Laravel applications by focusing on distinct actions rather than traditional MVC patterns. This package simplifies development by allowing you to encapsulate application logic into single-action classes that can be executed in various contexts like controllers, jobs, listeners, or commands.
Key Features
- Single Action Classes: Centralize the logic of specific tasks within single, reusable classes.
- Flexible Usage: Actions can be run as controllers, jobs, listeners, commands, or even plain objects.
- Simplifies Code: Reduces the need for separate controllers, form requests, and event listeners by consolidating functionality into action classes.
- Enhanced Focus: Shifts the development question from structuring based on design patterns to focusing on what the application needs to do.
Installation
Install the package via Composer:
composer require lorisleiva/laravel-actions
Basic Usage
- Create an Action: Use Artisan to generate a new action.
php artisan make:action PublishANewArticle
- Define Execution Contexts: Implement methods like
asController,asJob,asListener, orasCommanddepending on how the action should be used. - Running the Action:
- As an object:
PublishANewArticle::run($author, 'Title', 'Content'); - As a controller: Register the action in a routes file.
Route::post('articles', PublishANewArticle::class)->middleware('auth');
- As a listener: Link the action to an event.
Event::listen(NewProductReleased::class, PublishANewArticle::class);
- As an object:
Documentation
For detailed documentation on usage and additional features, visit laravelactions.com.
Laravel Actions simplifies application logic management by focusing on what actions your application needs to perform, making it a powerful package for developers looking to streamline their Laravel application development.