tedon/laravel-actor
Composer 安装命令:
composer require tedon/laravel-actor
包简介
A brand option to have specific action fields in model.
README 文档
README
A brand option to have auto generated specific action fields in model. Using this package helps you universalize fields along your team.
Installation
In order to add the capability to your laravel application, you should require it via composer.
composer require tedon/laravel-actor
Publish configuration file
By publishing configuration file, it is possible to edit predefined custom shortcut macros.
php artisan vendor:publish --provider="Tedon\LaravelActor\Providers\ActorServiceProvider" --tag="actor-config"
Usage
Basic Usage
You can use actor as a macro in migrations. Verb form of action is passed as the first argument.
Schema::table('users', function (Blueprint $table) { ... $table->actor('test'); ... });
In the provided example, $table->actor('test'); will create fields tester_id and tester_type
Shortcut Macros
You can use some macros as shortcuts. by default, creator and editor macros is defined.
Schema::table('users', function (Blueprint $table) { ... $table->creator(); $table->editor(); ... });
In the provided example, fields creator_id, creator_type, editor_id and editor_type is created for users table.
Define Custom Shortcut Macros
use the provided config file to add or remove custom shortcut macros.
return [ 'custom-macros' => [ 'edit', 'approve', ] ];
In the provided example, the create macro is remove and the approve macro is added to the code;
Model Traits
There is a trait provided in the package: Actorable. The actorable function is defined to handle auto-set feature.
use \Tedon\LaravelActor\Traits\Actorable; class User { use Actorable; public function actorable(): array { return [ 'actions' => [ 'edit' ] ]; } }
In the example above, edit-related fields is set on model update automatically.
Currently, The create action is also available to be auto-set.
Retrieve Actor Data
Though you can access to fields directly by field name, there are some functions to access actor data.
Available Methods:
The following methods is added by using Actorable trait on the model. It is totally clear that the macros in migration
should be used before to generate related columns.
Get Actor ID:
Retrieve actor id of given action.
getActorId(string $action): int|string; // example output: 13
Get Actor Type:
Retrieve actor type of given action.
getActorType(string $action): ?string; // example output: "\App\Models\User"
Get Acted At:
Retrieve the time when given action is acted at.
getActedAt(string $action): ?Carbon; // example output: "2023-04-30 15:30:04"
Get Actor:
Retrieve the actor model.
getActor(string $action): ?Model;
Get Act:
Returns an array containing all above data.
getAct(string $action): array; // example output: [ // 'editor_id' => 13, // 'editor_type' => "\App\Models\User", // 'edited_at' => "2023-04-30 15:30:04", // ]
Set Actor Data
The action field can be set with methods below.
Touch Action
This method is provided to set all action fields at the same time with the authenticated user.
touchAction(string $action, bool $isForce = false): void;
Clear Action
This method is provided to clear all action fields at the same time.
cleanAction(string $action): void;
Check and filter Actor Data
These accessories are used for checking and filtering action data
Check If Is Acted By
This method is used for checking if the model is acted by specific user on a specific action
isActedBy(string $action, ?Authenticatable $user): bool;
returns true if the model is acted on the action by the given user.
Acted By Scope
There is a scope provided for filtering the actorable model data to get record with the given actor on the given action.
$query ... ->actedBy('create', $user) ...
The expression above scopes actorable model query with the given action and given authenticatable user.
License
The Laravel Actor package is open-sourced software licensed under the MIT license.
tedon/laravel-actor 适用场景与选型建议
tedon/laravel-actor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 124 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「action」 「actor」 「Tedon」 「LaravelAction」 「LaravelActor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tedon/laravel-actor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tedon/laravel-actor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tedon/laravel-actor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova asset.
Generate Laravel actions
Symfony Workflow Bundle by Sprint-F.RU
Symfony WolffloW Bundle by Sprint-F.RU
Create mail from controller action render
Yii2-article is a module offering basic CMS-functionality
统计信息
- 总下载量: 124
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-17