定制 johndivam/check-duplicate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

johndivam/check-duplicate

最新稳定版本:v1.0

Composer 安装命令:

composer require johndivam/check-duplicate

包简介

Check for duplicate rows based on specified columns across multiple models

README 文档

README

The CheckDuplicates package is a Laravel package designed to check for duplicate rows in specified models based on configurable columns. It supports both regular and soft-deleted models and logs the results daily for easy review.

Features

  • Check for duplicate rows in one or more models.
  • Supports multiple columns for duplicate checks.
  • Configurable to include soft-deleted rows.
  • Daily logging of duplicate checks for easy monitoring.

Installation

You can install the package via Composer:

composer require johndivam/check-duplicates

Configuration

Add the service provider to config/app.php under providers:

'providers' => [
    Johndivam\CheckDuplicate\CheckDuplicatesServiceProvider::class,
],

After installation, publish the configuration file:

php artisan vendor:publish --provider="Johndivam\CheckDuplicate\CheckDuplicatesServiceProvider"

This will create a configuration file at config/check-duplicates.php.

Configuration Options

Edit the config/check-duplicates.php file to specify the models and columns you want to check for duplicates:

return [
    'models' => [
        [
            'model' => \App\Models\Task::class,
            'columns' => ['project_id', 'name'],
            'with_deletes' => false, // Set to false to exclude soft-deleted records
        ],
        [
            'model' => \App\Models\Order::class,
            'columns' => ['cart_id'],
            'with_deletes' => true, // Set to true to include soft-deleted records
        ],
        // Add more models as needed
    ],
];

Usage

The package runs a scheduled command to check for duplicates every minute. You can manually trigger the check with:

php artisan duplicates:check

You may also schedule this command in your App\Console\Kernel.php file to run at your desired interval:

protected function schedule(Schedule $schedule)
{
    $schedule->command('duplicates:check')->everyMinute();
}

Logging

The results of the duplicate checks are logged daily in the storage/logs/ directory. The log file is named as check_duplicates-YYYY-MM-DD.log, where YYYY-MM-DD is the date the log was created.

Example Log Entry

[2024-10-28 12:00:00] check_duplicates.INFO: Duplicate entries found in model App\Models\Task. Details: [{"project_id":1,"name":"Test Task"}]

Contributing

If you would like to contribute to this package, please fork the repository and submit a pull request.

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-28