haykel/laravel-action-maker
Composer 安装命令:
composer require haykel/laravel-action-maker
包简介
A Laravel package to generate Action classes with optional DB transactions and Pest tests.
README 文档
README
A Laravel package to generate Action classes with automatic transaction handling, custom namespaces, and Pest test generation.
Features
- Transactions by Default: Automatically wraps logic in
DB::transaction(configurable) - Smart Naming: Auto-appends configurable suffixes (e.g.,
CreateUser→CreateUserAction) - Folder Support: Easily organize actions into subfolders via
--folder - Test Generation: Generates a corresponding Pest unit test with
--with-test - Customizable: Publishable stubs and configuration
- Laravel 10, 11, & 12: Works with modern Laravel versions
- PHP 8.1+: Supports PHP 8.1, 8.2, and 8.3
Installation
You can install the package via composer:
composer require haykel/laravel-action-maker
The package will automatically register itself via Laravel's package auto-discovery.
Publish Configuration (Optional)
To customize the default behavior, publish the configuration file:
php artisan vendor:publish --tag=action-maker-config
This will create config/action-maker.php where you can customize:
- Default namespace for actions
- Class suffix
- Transaction behavior
- Test generation preferences
Publish Stubs (Optional)
To customize the generated code templates:
php artisan vendor:publish --tag=action-maker-stubs
This will publish stubs/action.stub and stubs/pest.stub to your project root.
Usage
Basic Action
php artisan make:action CreateUser
Result: app/Actions/CreateUserAction.php
<?php namespace App\Actions; use Illuminate\Support\Facades\DB; class CreateUserAction { public function execute() { return DB::transaction(function () { // TODO: Implement action logic here return true; }); } }
With Subfolder
php artisan make:action UpdateProfile --folder=User/Profile
Result: app/Actions/User/Profile/UpdateProfileAction.php
Without Transactions
php artisan make:action SendNotification --no-transaction
Result: Creates action without the DB::transaction wrapper.
With Pest Test
php artisan make:action DeleteUser --with-test
Result:
app/Actions/DeleteUserAction.phptests/Unit/Actions/DeleteUserActionTest.php
Combined Options
php artisan make:action ProcessPayment --folder=Billing/Payment --with-test --no-transaction
Configuration
The config/action-maker.php file contains the following options:
return [ // Default namespace (relative to App\) 'namespace' => 'Actions', // Suffix automatically appended to class names 'class_suffix' => 'Action', // Wrap execute() in DB::transaction by default 'use_transactions' => true, // Generate Pest tests by default (even without --with-test) 'generate_tests' => false, ];
Testing
This package includes comprehensive Pest tests. To run the tests:
composer install
composer test
For test coverage report:
composer test-coverage
Development Setup
If you want to contribute or modify this package locally:
- Clone the repository:
git clone https://github.com/HaykelRekik/laravel-action-maker.git
cd laravel-action-maker
- Install dependencies:
composer install
- Run tests:
composer test
Testing in a Local Laravel Project
To test the package in a local Laravel project before publishing:
- In your Laravel project's
composer.json, add a local repository:
{
"repositories": [
{
"type": "path",
"url": "../laravel-action-maker"
}
]
}
- Require the package:
composer require haykel/laravel-action-maker:@dev
- Test the commands:
php artisan make:action TestAction php artisan make:action AnotherAction --with-test --folder=User
Troubleshooting
Composer Dependency Conflicts
If you encounter dependency conflicts during installation, ensure your Laravel project meets the minimum requirements:
- PHP ^8.1|^8.2|^8.3
- Laravel ^10.0|^11.0|^12.0
The package uses illuminate/support and illuminate/contracts to ensure maximum compatibility.
Generated Classes Not Found
Run composer autoload dump after generating new classes:
composer dump-autoload
Credits
License
The MIT License (MIT). Please see License File for more information.
haykel/laravel-action-maker 适用场景与选型建议
haykel/laravel-action-maker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「command」 「laravel」 「action」 「pest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 haykel/laravel-action-maker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 haykel/laravel-action-maker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 haykel/laravel-action-maker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
Shell command module for PHP.
Library with classes to help you do batch.
Command bus implementation: Commands and domain events
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-20