dominion-solutions/filament-cascading-actions
Composer 安装命令:
composer require dominion-solutions/filament-cascading-actions
包简介
A filament package that implements cascading actions and bulk actions.
关键字:
README 文档
README
Skip To Installation Instructions
What does this package do?
This package brings cascading database operations to Filament, utilizing Actions. There are times that you may not want a CASCADE option on your foreign relationsips in the database, as well as times where you may not own the data schema outright. This package fills that gap. The cascading actions can be included as Bulk Actions, on a listing table, as well as a singular action, on either an edit page or on a record on a table. It offers no UI components itself, but rather uses the UI elements for the action that it is wrapping (DeleteAction for example).
Why Would you want to do a Cascading Action on a relationship?
Consider the following schema:
Tax Rate Amount Model
// ...
class TaxRateAmount extends BaseModel
{
//...
/**
* Return the tax rate relation.
*/
public function taxRate(): BelongsTo
{
return $this->belongsTo(TaxRate::class);
}
/**
* Return the tax class relation.
*/
public function taxClass(): BelongsTo
{
return $this->belongsTo(TaxClass::class);
}
}
Tax Rate Model:
// ...
class TaxRate extends BaseModel
{
//...
/**
* Return the tax zone relation.
*/
public function taxZone(): BelongsTo
{
return $this->belongsTo(TaxZone::class);
}
/**
* Return the tax rate amounts relation.
*/
public function taxRateAmounts(): HasMany
{
return $this->hasMany(TaxRateAmount::class);
}
}
In this case, deleting the TaxRate that is associated with a TaxRateAmount will cause a foreign key constraint error in the database. In this case, the DeleteCascadingAction and DeleteCascadingBulkAction Actions would be the appropriate actions to use, using ->relationship('taxRateAmounts') on each.
Currently Supported Cascading Actions
Currently the following cascading actions are supported:
- Delete:
`DominionSolutions\FilamentCascadingActions\Actiouns\DeleteCascadingAction` - BulkDelete:
`DominionSolutions\FilamentCascadingActions\Tables\Actions\DeleteCascadingBulkAction`
The Relationships Method
The relationships() method is exposed on each of the actions. Right now the default action is to not traverse the relathionships at all, effectively acting like a the regular Filament Action that it wraps. It accepts an array of strings with the names of the relationships that you would like to modify along with the parent record.
That's great, but what is a cascading database action?
In the context of databases, "cascading" refers to the way changes in one part of the database can affect other related parts. Specifically, cascading operations typically involve actions like inserting, updating, or deleting data.
1. Cascading Inserts:
- Suppose you have two tables, let's call them Table A and Table B, and there's a relationship between them.
- A cascading insert means that when you add a new record to Table A, related records in Table B are automatically created. This ensures that the data in both tables stay connected.
2. Cascading Updates:
- Let's say you change the value of a particular field in a record of Table A. With cascading updates, the corresponding records in Table B that are linked to the updated record in Table A also get automatically updated to reflect the change.
3. Cascading Deletes:
- Similarly, when you delete a record in Table A, cascading deletes ensure that associated records in Table B are also deleted. This helps maintain data integrity, preventing orphaned records in related tables.
Installation
You can install the package via composer:
composer require dominion-solutions/filament-cascading-actions
You can publish the config file with:
php artisan vendor:publish --tag="filament-cascading-actions-config"
This is the contents of the published config file:
return [
return [
'enable-cascading-actions' => true,
'prompt-before-cascading' => true,
'bulk-delete-action-name' => 'Delete',
];
Usage
Within the Header Actions for a Filament Page:
protected function getHeaderActions(): array
{
return [
\DominionSolutions\FilamentCascadingActions\Actions\DeleteCascadingAction::make()
->relationships('taxRateAmounts'),
];
}
Using a Bulk Action on a Table:
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
DeleteCascadingBulkAction::make()->relationships('taxRateAmounts'),
]),
]);
}
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
dominion-solutions/filament-cascading-actions 适用场景与选型建议
dominion-solutions/filament-cascading-actions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Relationships」 「delete」 「cascade」 「cascading」 「dominion-solutions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dominion-solutions/filament-cascading-actions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dominion-solutions/filament-cascading-actions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dominion-solutions/filament-cascading-actions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Interface for Babel Street Text Analytics
Adds nested resources routing support along with related actions and relationship handlers to the Yii RESTful API framework
SoftDelete plugin for CakePHP
Laravel console command for deleting temp files and associated model instances.
Adds KeyBy('id') to Eloquent relationships
Automatic auditing for Eloquent relationship changes (attach, detach, sync) using Laravel Auditing
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-20