Download the PHP package hosnyadeeb/laravel-model-actions without Composer
On this page you can find all versions of the php package hosnyadeeb/laravel-model-actions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-model-actions
Laravel Model Actions
A Laravel package for generating action classes for Eloquent models with built-in CRUD operations.
Features
- 🚀 Artisan Command - Generate all action classes for a model with a single command
- 📦 Base Action Classes - Extensible base classes for Index, Show, Store, Update, and Delete operations
- 🎯 Static & Instance Execution - Run actions statically or via helper function
- 🔧 Customizable Stubs - Publish and customize action stubs to match your coding style
- ✅ Confirmation Dialogs - Warns before overwriting existing actions
- 🎨 Clean Architecture - Follows single responsibility principle with dedicated action classes
- 🪝 Lifecycle Hooks - Before/after hooks for custom logic injection
- 📦 Bulk Operations - BulkDelete and BulkUpdate actions for multiple records
- 🔍 Query Filters - Built-in search, sort, and date range filtering
- 🔍 Query Filters - Built-in search, sort, and date range filtering
Installation
Install the package via Composer:
The package will automatically register its service provider.
Publish Assets (Optional)
Publish Configuration
Publish Stubs for Customization
This allows you to customize the generated action classes, including the Base classes.
Once published, you can edit the files in stubs/model-actions/. The command will automatically use these custom stubs when generating new actions.
Example:
stubs/model-actions/Index.stub-> CustomizesUserIndexActionstubs/model-actions/base/IndexAction.stub-> CustomizesApp\Actions\_Base\IndexAction
Usage
Generate Actions for a Model
This will create the following files in app/Actions/User/:
UserIndexAction.phpUserShowAction.phpUserStoreAction.phpUserUpdateAction.phpUserDeleteAction.php
Generate a Custom Action
Create a single custom action for a model:
This creates app/Actions/User/UserActivateAction.php with hooks ready to use.
Running Actions
There are three ways to execute an action:
1. Static Method (Recommended)
2. Helper Function
3. Instance Method
Customizing Actions
Using Custom Query Builder
The IndexAction provides a customBuilder method for complex queries:
Overriding Store/Update Logic
In Controllers
Lifecycle Hooks
All actions support before(), after(), and onError() hooks for injecting custom logic:
Using Hooks
Hook Execution Order
before()- Runs before the main action logichandle()- Main action logic executesafter($result)- Runs after successful execution (can modify result)onError($e)- Runs if an exception occurs (then re-throws)
Custom Actions
Create custom business logic actions beyond CRUD operations.
Creating a Custom Action
Use the artisan command:
Or create manually by extending the base Action class:
Running Custom Actions
Composite Actions
Chain multiple actions together:
Using Traits in Custom Actions
Combine multiple traits for enhanced functionality:
Query Filters
The Filterable trait provides powerful search, sort, and date filtering capabilities for Index actions.
Using Filters
Available Filter Parameters
| Parameter | Description | Example |
|---|---|---|
search or q |
Search term | ?search=john |
sort or order_by |
Column to sort by | ?sort=name |
direction or order_dir |
Sort direction (asc/desc) | ?direction=asc |
date_from or from |
Filter from date | ?date_from=2024-01-01 |
date_to or to |
Filter to date | ?date_to=2024-12-31 |
| Any other key | Where condition | ?status=active&role=admin |
Usage in Controller
Searching Relationships
Define relationship columns with dot notation:
Bulk Actions
Perform operations on multiple records at once.
BulkDeleteAction
BulkUpdateAction
Configuration
After publishing the config file, you can customize:
Customizing Stubs
After publishing stubs, you can find them in stubs/model-actions/. Modify these files to change the generated action structure:
Index.stub- Template for index actionsShow.stub- Template for show actionsStore.stub- Template for store actionsUpdate.stub- Template for update actionsDelete.stub- Template for delete actions
Directory Structure
After generating actions, your project will have:
Testing
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-model-actions with dependencies
illuminate/console Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/filesystem Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0