opscale-co/actions
Composer 安装命令:
composer require opscale-co/actions
包简介
Loris Leiva - Laravel Actions extension with Nova additions
README 文档
README
At Opscale, we’re passionate about contributing to the open-source community by providing solutions that help businesses scale efficiently. If you’ve found our tools helpful, here are a few ways you can show your support:
⭐ Star this repository to help others discover our work and be part of our growing community. Every star makes a difference!
💬 Share your experience by leaving a review on Trustpilot or sharing your thoughts on social media. Your feedback helps us improve and grow!
📧 Send us feedback on what we can improve at feedback@opscale.co. We value your input to make our tools even better for everyone.
🙏 Get involved by actively contributing to our open-source repositories. Your participation benefits the entire community and helps push the boundaries of what’s possible.
💼 Hire us if you need custom dashboards, admin panels, internal tools or MVPs tailored to your business. With our expertise, we can help you systematize operations or enhance your existing product. Contact us at hire@opscale.co to discuss your project needs.
Thanks for helping Opscale continue to scale! 🚀
Description
One logic unit to rule them all.
Encapsulate your business logic in atomic, self-contained classes and reuse them across your entire application stack. Write once, use everywhere.
This package extends Laravel Actions with support for:
- Laravel Nova Actions - Use actions directly as Nova actions
- Laravel MCP Tools - Use actions as Model Context Protocol tools for AI
The same logic can serve multiple audiences:
- For end users → Nova Actions in your admin panel
- For administrators → Artisan commands in the terminal
- For external systems → API endpoints via controllers
- For AI agents → MCP tools for intelligent automation
Installation
You can install the package via composer:
composer require opscale-co/actions
The package is automatically registered via Laravel's package discovery.
Usage
Real-World Example: ResetPassword
Here's a complete example showing how a single ResetPassword action can serve your entire application:
use Opscale\Actions\Action; class ResetPassword extends Action { public function identifier(): string { return 'reset-password'; } public function name(): string { return 'Reset Password'; } public function description(): string { return 'Resets a user\'s password'; } public function parameters(): array { return [ [ 'name' => 'email', 'description' => 'The email address of the user', 'type' => 'string', 'rules' => ['required', 'email', 'exists:users,email'], ], [ 'name' => 'password', 'description' => 'The new password', 'type' => 'string', 'rules' => ['required', 'string', 'min:8'], ], [ 'name' => 'password_confirmation', 'description' => 'Confirm the new password', 'type' => 'string', 'rules' => ['required', 'string', 'same:password'], ], ]; } public function handle(array $attributes = []): array { $this->fill($attributes); $validated = $this->validateAttributes(); $user = User::where('email', $validated['email'])->firstOrFail(); $user->update(['password' => Hash::make($validated['password'])]); return [ 'success' => true, 'message' => 'Password reset successfully' ]; } }
Prefill & Options
Two optional hooks let you trim what each adapter solicits from the user and what the action takes as authoritative:
| Hook | Role | Shown to user |
|---|---|---|
prefill() |
Authoritative defaults for parameters. Wins over user input. Hidden in every adapter. | Hidden |
options() |
Choice list per parameter for the values the user IS asked for. Nova renders a Select, Artisan renders a choice prompt, MCP exposes an enum. |
Visible |
class UpdateStatus extends Action { public function parameters(): array { return [ ['name' => 'status', 'description' => 'New status', 'type' => 'string', 'rules' => ['required', 'string']], ['name' => 'note', 'description' => 'Optional reason', 'type' => 'string', 'rules' => ['nullable', 'string', 'max:500']], ]; } public function prefill(): array { return ['note' => 'Updated via automated pipeline.']; } public function options(): array { return ['status' => ['active', 'inactive', 'pending']]; } }
Prefilled values always win over user-supplied values (an API client sending note => 'override' will still see the prefilled note in handle()).
One Action, Multiple Contexts
Now this single class can be used everywhere:
// For end users → Nova Action in admin panel // Register in your Nova Resource: public function actions(NovaRequest $request) { return [ ResetPassword::make() ]; } // For administrators → Artisan command // php artisan reset-password --email=user@example.com --password=newpass123 $this->commands([ ResetPassword::class, ]); // For external systems → API endpoint Route::post('/api/reset-password', ResetPassword::class); // For AI agents → MCP tool // Register in your MCP Server: class PlatformServer extends Server { protected array $tools = [ ResetPassword::class ]; }
Opinionated Design
This package is an opinionated implementation that enforces the use of WithAttributes from Laravel Actions. All input data flows through fill() and validateAttributes(), ensuring consistent parameters validation and attribute handling across all contexts.
The package provides a default behavior for all four audiences (Nova Actions, Artisan Commands, Controllers, and MCP Tools), so your actions work out of the box without additional configuration, but it can be overriden using the speficic methods for each output.
Testing
npm run test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email development@opscale.co instead of using the issue tracker.
Credits
Built by Opscale on top of:
- Laravel Actions by Loris Leiva
- Laravel Nova by Laravel
- Laravel MCP by Laravel
License
The MIT License (MIT). Please see License File for more information.
opscale-co/actions 适用场景与选型建议
opscale-co/actions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 958 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「nova」 「tool」 「laravel」 「opscale」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 opscale-co/actions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 opscale-co/actions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 opscale-co/actions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
Backend Google Sign On for Magento 2
An app setting manager tool for laravel nova
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
统计信息
- 总下载量: 958
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-18
