haykel/laravel-action-maker 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

haykel/laravel-action-maker

最新稳定版本:v1.1.1

Composer 安装命令:

composer require haykel/laravel-action-maker

包简介

A Laravel package to generate Action classes with optional DB transactions and Pest tests.

README 文档

README

Latest Version on Packagist Total Downloads Tests

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., CreateUserCreateUserAction)
  • 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.php
  • tests/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:

  1. Clone the repository:
git clone https://github.com/HaykelRekik/laravel-action-maker.git
cd laravel-action-maker
  1. Install dependencies:
composer install
  1. Run tests:
composer test

Testing in a Local Laravel Project

To test the package in a local Laravel project before publishing:

  1. In your Laravel project's composer.json, add a local repository:
{
    "repositories": [
        {
            "type": "path",
            "url": "../laravel-action-maker"
        }
    ]
}
  1. Require the package:
composer require haykel/laravel-action-maker:@dev
  1. 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.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-20