swalbrun/filament-regex-import
最新稳定版本:2.0.1
Composer 安装命令:
composer require swalbrun/filament-regex-import
包简介
This Filament Plugin will enable you to import files to upsert models by matching columns via regex.
README 文档
README
This Filament Plugin will enable you to import files to upsert models by matching columns via regex.
Installation
You can install the package via composer:
composer require swalbrun/filament-regex-import
Create a mapper using the make command
php artisan filament:make-filament-import-mapper UserMapper
You can publish the config file with:
php artisan vendor:publish --tag="filament-regex-import-config"
This is the contents of the published config file:
return [ 'accepted_mimes' => [ 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain', 'csv', ], 'mappers' => [ ], 'navigation_group' => 'Import', ];
You can publish the translation file with:
php artisan vendor:publish --tag="filament-regex-import-translations"
Features
Matching header columns with configured regex
Matches given mappers' regex with model columns
| Username | |
|---|---|
| Sebastian | sebastian@walbrun-consulting.de |
| John | john@doe.test |
public function propertyMapping(): Collection { return collect([ 'name' => '/(user|first|last)?name)/i', 'email' => '/(E(-|_)?)?Mail/i', ]); }
Detecting overlapping regexes
Fails in case two regexes are matching the same column.
Upserting models via unique keys
Creates or updates models taking care of the given unique columns
public function uniqueColumns(): array { return [ 'email', ]; }
Relating models
Call hooks for relating found models. The hooks will get called in case all hooks arguments models have been found
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(); } }; ]); }
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.
统计信息
- 总下载量: 129
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-21