swalbrun / filament-regex-import
此 Filament 插件将使您能够通过匹配列来导入文件,从而更新模型。
0.2.1
2023-06-08 13:22 UTC
Requires
- php: ^8.0
- filament/filament: ^2.17
- illuminate/contracts: ^9.0|^10.0
- maatwebsite/excel: ^3.1
- spatie/laravel-package-tools: ^1.13.5
Requires (Dev)
- captainhook/captainhook: ^5.16
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- pestphp/pest-plugin-livewire: ^1.0
- pestphp/pest-plugin-parallel: ^1.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- ramsey/conventional-commits: ^1.5
- spatie/laravel-permission: ^5.10
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-09-09 05:50:50 UTC
README
此 Filament 插件将使您能够通过匹配列来导入文件,从而更新模型。
安装
您可以通过 composer 安装此包
composer require swalbrun/filament-regex-import
使用 make 命令创建映射器
php artisan filament:make-filament-import-mapper UserMapper
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="filament-regex-import-config"
这是已发布配置文件的内容
return [ 'accepted_mimes' => [ 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain', 'csv', ], 'mappers' => [ ], 'navigation_group' => 'Import', ];
您可以使用以下命令发布翻译文件
php artisan vendor:publish --tag="filament-regex-import-translations"
功能
通过配置的 regex 匹配标题列
匹配给定映射器的 regex 与模型列
public function propertyMapping(): Collection { return collect([ 'name' => '/(user|first|last)?name)/i', 'email' => '/(E(-|_)?)?Mail/i', ]); }
检测重叠的 regex
如果两个 regex 匹配相同的列,则失败。
通过唯一键更新模型
创建或更新模型,同时注意给定的唯一列
public function uniqueColumns(): array { return [ 'email', ]; }
关联模型
调用关联找到的模型的钩子。如果所有钩子参数模型都已找到,则将调用钩子
public function relatingClosures(): Collection { return collect([ fn (User $user, Role $role) => $user->roles()->saveMany([$role]), fn (User $user) => event(new UserImported($user)), // Only gets called if a user, role and post with the matching type has been found by import function (User $user, Role $role, Post $post) { if ($role->is('user')) { $user->post()->associate($post)->save(); } }; ]); }
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请审查 我们的安全策略 了解如何报告安全漏洞。
致谢
许可
MIT 许可证(MIT)。有关更多信息,请参阅 许可文件。