aesircloud/laravel-actions
Composer 安装命令:
composer require aesircloud/laravel-actions
包简介
A simple Actions package for Laravel with job/queue/controller support.
README 文档
README
A simple actions package for Laravel.
Requirements: PHP 8.4+ and Laravel 12.
Features
- Single-Class Workflow: Write your logic once in a single
Actionclass. No need to duplicate code in controllers, jobs, or other classes. - Run Synchronously or as a Queued Job
- Call
MyAction::run($data)for immediate, synchronous execution. - Call
MyAction::dispatch($data)to run the action as a queued job.
- Call
- Controller Integration
- Use your
Actionas an invokable controller with __invoke(). - Or define multiple methods (e.g., index, store) and treat it like a standard Laravel controller.
- Override
asController()to parse/validate request data before callinghandle().
- Use your
Installation
You can install the package via composer:
composer require aesircloud/laravel-actions
Laravel’s package auto-discovery will register the service provider automatically. If you need to manually register it, add the following to your config/app.php providers array:
AesirCloud\LaravelActions\Providers\ActionServiceProvider::class,
PUBLISHING STUBS
To customize the stub files used for scaffolding, publish the package stubs:
php artisan vendor:publish --tag=actions-stubs
Usage
To scaffold a new action, run the following command:
php artisan make:action {ActionName}
This will create a new action class in the app/Actions directory.
Basic Example
php artisan make:action CreateUser
Creates an action file under app/Actions/CreateUser.php.
namespace App\Actions; use AesirCloud\LaravelActions\Action; class CreateUser extends Action { public function handle() { // Your logic here... } }
Running Synchronously
You can run the action synchronously by calling the run method on the action class:
$user = CreateUser::run($data);
Running as a Job
You can run the action as a job by calling the dispatch method on the action class:
$pending = CreateUser::dispatch($data);
Running as an Invokable Controller
// app/Actions/MyAction.php namespace App\Actions; use AesirCloud\LaravelActions\Action; use Illuminate\Http\Request; class MyAction extends Action { public function handle(): mixed { return 'Hello world!'; } public function asController(Request $request): mixed { // e.g., $data = $request->validate([...]); return $this->handle(); } }
// routes/web.php use App\Actions\MyAction; use Illuminate\Support\Facades\Route; Route::get('/my-action', MyAction::class);
Running as a Multi-Method Controller
namespace App\Actions; use AesirCloud\LaravelActions\Action; use Illuminate\Http\Request; class MyAction extends Action { public function handle(): mixed { return 'Default logic (if you still want to call it externally).'; } // Typical controller method: public function index(Request $request): mixed { return 'Called via index method!'; } public function store(Request $request): mixed { return 'Called via store!'; } }
// routes/web.php Route::get('/my-action', [MyAction::class, 'index']); Route::post('/my-action', [MyAction::class, 'store']);
Security
If you've found a bug regarding security please mail security@aesircloud.com instead of using the issue tracker.
LICENSE
The MIT License (MIT). Please see License file for more information.
aesircloud/laravel-actions 适用场景与选型建议
aesircloud/laravel-actions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 aesircloud/laravel-actions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aesircloud/laravel-actions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-28