teguh02 / filament-db-sync
此软件包允许同步两个不同的 Laravel Filament 应用程序数据库
v1.1
2024-09-05 13:17 UTC
Requires
- php: ^8.1
- filament/filament: ^3.0
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.1
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
README
安装
您可以通过 composer 安装此软件包
composer require teguh02/filament-db-sync
面板配置
在您的面板服务提供程序中安装库
<?php use Teguh02\FilamentDbSync\FilamentDbSync; public function panel(Panel $panel): Panel { return $panel // ... another filament configuration ->plugins([ FilamentDbSync::make(), ]); }
配置文件和迁移
发布配置和迁移
php artisan vendor:publish --provider="Teguh02\FilamentDbSync\FilamentDbSyncServiceProvider"
php artisan migrate
用法
模型配置
在您的模型类中,添加 fillable
和 casts
属性。例如,如果我们有一个名为 Items 的模型,则模型配置应如下所示
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Items extends Model { use HasFactory; // Define the table property // if the table name is different // protected $table = 'items'; // Define the primary key property // if the primary key is different // protected $primaryKey = 'id'; // Define the fillable property to // allow mass assignment on the model // and the database sync process protected $fillable = [ 'name', 'description', 'price', 'stock', 'expired_at', ]; // Define the casts property to // automatically cast the data type // of the model attributes protected $casts = [ 'stock' => 'integer', 'price' => 'integer', 'expired_at' => 'date', ]; }
db_sync.php 配置
对于插件配置,您可以根据需要手动调整。
<?php // config for Teguh02/FilamentDbSync return [ /** * The host where the data will be synced */ 'sync_host' => env('SYNC_HOST', 'https://'), /** * The token to be used for authentication */ 'auth_token' => env('SYNC_TOKEN', 'default_token'), /** * Models configuration */ 'models' => [ /** * If set to true, the package will * automatically scan all models in the app/Models directory */ 'auto_scan' => env('AUTO_SCAN_MODELS', true), /** * If auto_scan is set to true, * this configuration will be used to exclude models * which will not be synced */ 'excluded' => [ // App\Models\User::class, ], /** * When auto_scan is set to false, * this configuration will be used to include models */ 'included' => [ // App\Models\User::class, ], /** * The column to be used as the key * when syncing data */ 'column_as_key' => [ // class => column App\Models\User::class => 'email', // or you can use the table name // table_name => column // 'users' => 'email', ], ], /** * Sync configuration */ 'sync' => [ /** * The action to be taken when there is duplicate data * * Available options: * - update : update the existing data * - duplicate : create a new data with the same data */ 'duplicate_data_action' => env('DUPLICATE_DATA_ACTION', 'update'), ], ];
队列配置
因为这个插件使用作业功能来执行大量数据,请根据您的需要设置队列驱动程序。
#QUEUE_CONNECTION=sync
QUEUE_CONNECTION=database
屏幕截图
贡献
有关详细信息,请参阅CONTRIBUTING。
安全漏洞
请审查我们的安全策略,了解如何报告安全漏洞。
鸣谢
许可
MIT 许可证(MIT)。有关更多信息,请参阅许可文件。