mateusz-peczkowski/nova-heartbeat-resource-field 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mateusz-peczkowski/nova-heartbeat-resource-field

最新稳定版本:1.0.6

Composer 安装命令:

composer require mateusz-peczkowski/nova-heartbeat-resource-field

包简介

Heartbeat for resources to block editing same resource with 2 or more people

README 文档

README

NovaHeartbeatResourceField

Heartbeat Resource Field

This package provides a custom Nova field that will like heartbeat monitor watch who is editing currently the resource.

On a listing/details there will be information who is currently editing and as well another person will be blocked from editing the same resource to not overlap changes.

Package is made for Laravel Nova ^4 and it works as well with Laravel Nova ^5.

Installation

You can install the package via composer:

composer require mateusz-peczkowski/nova-heartbeat-resource-field

Migrations

After installation, you need to run the migration to create the table that will store the heartbeat data.

php artisan migrate

Publish package (optional)

Publish the configuration file to customize the settings of the package (check bellow for more details).

php artisan vendor:publish --provider="MateuszPeczkowski\NovaHeartbeatResourceField\HeartbeatResourceServiceProvider"

Configuration

The package provides a configuration file that allows you to customize the settings of the package.

return [
    'table_name'            => 'nova_heartbeats',
    'heartbeat_model'       => \MateuszPeczkowski\NovaHeartbeatResourceField\Models\HeartbeatResource::class,
    'heartbeat_interval'    => env('NOVA_HEARTBEAT_INTERVAL', 5 * 1000), // 5 seconds
    'heartbeat_timeout'     => env('NOVA_HEARTBEAT_TIMEOUT', 60 * 1000), // 1 minute
    'heartbeat_guard'       => 'web',
    'heartbeat_guard_name'  => 'name',
    'heartbeat_guard_email' => 'email',
    'heartbeat_avatar_url'  => null,
];

Usage

Nova Resource Field

To install this field in your Nova resource, you need to add the following code to the fields method of your resource.

use MateuszPeczkowski\NovaHeartbeatResourceField\NovaHeartbeatResourceField;

NovaHeartbeatResourceField::make('Heartbeat')
    ->resourceId($this->id),

Optionally you can allow to retake the resource by adding the following code

use MateuszPeczkowski\NovaHeartbeatResourceField\NovaHeartbeatResourceField;

NovaHeartbeatResourceField::make('Heartbeat')
    ->resourceId($this->id)
    ->allowRetake(),

Then on details view you will have additional button to retake the resource.

Nova Resource Trait

Add this trait to your Nova resource

use MateuszPeczkowski\NovaHeartbeatResourceField\Traits\HasNovaHeartbeats;

class YourResource extends Resource
{
    use HasNovaHeartbeats;
}

Model Trait

Add this trait to your Model

use MateuszPeczkowski\NovaHeartbeatResourceField\Traits\HasHeartbeats;

class YourModel extends Model
{
    use HasHeartbeats;
}

Clearing expired heartbeats (recommended)

In case of failure of removing the heartbeat, you can use the following command to remove all the heartbeats that are older than the timeout.

$schedule->command('heartbeat:clear-expired')->everyMinute();

统计信息

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

GitHub 信息

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

其他信息

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