A Laravel package to generate Action classes with automatic transaction handling, custom namespaces, and Pest test generation.
DB::transaction (configurable)CreateUser → CreateUserAction)--folder--with-testYou can install the package via composer:
composer require haykel/laravel-action-maker
The package will automatically register itself via Laravel's package auto-discovery.
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:
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.
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;
});
}
}
php artisan make:action UpdateProfile --folder=User/Profile
Result: app/Actions/User/Profile/UpdateProfileAction.php
php artisan make:action SendNotification --no-transaction
Result: Creates action without the DB::transaction wrapper.
php artisan make:action DeleteUser --with-test
Result:
app/Actions/DeleteUserAction.phptests/Unit/Actions/DeleteUserActionTest.phpphp artisan make:action ProcessPayment --folder=Billing/Payment --with-test --no-transaction
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,
];
This package includes comprehensive Pest tests. To run the tests:
composer install
composer test
For test coverage report:
composer test-coverage
If you want to contribute or modify this package locally:
git clone https://github.com/HaykelRekik/laravel-action-maker.git
cd laravel-action-maker
composer install
composer test
To test the package in a local Laravel project before publishing:
composer.json, add a local repository:{
"repositories": [
{
"type": "path",
"url": "../laravel-action-maker"
}
]
}
composer require haykel/laravel-action-maker:@dev
php artisan make:action TestAction
php artisan make:action AnotherAction --with-test --folder=User
If you encounter dependency conflicts during installation, ensure your Laravel project meets the minimum requirements:
The package uses illuminate/support and illuminate/contracts to ensure maximum compatibility.
Run composer autoload dump after generating new classes:
composer dump-autoload
The MIT License (MIT). Please see License File for more information.