sacred96/timeline

使用 Laravel 轻松创建时间线

1.0.1 2021-03-24 06:11 UTC

This package is auto-updated.

Last update: 2024-09-24 14:16:23 UTC


README

创建具有不同模型的时间线历史记录

简介

此包允许您将时间线服务添加到您的 Laravel ^5.8 应用程序中

安装

在命令行中运行

composer require sacred96/timeline

发布资产

php artisan vendor:publish

运行迁移

php artisan migrate

使用方法

您可以指定不同的模型作为参与者。可选地,您可以将模型指定为时间线发起者,使其成为时间线的所有者。例如,您可以有 InvoiceCompanies 模型作为时间线的参与者

主要思想

您通过指定多个模型作为故事参与者来创建时间线历史记录。如果参与者中有一个是发起模型,则它必须使用 TimelineInitiator 特性。例如,对于文章审核的历史记录,文章将是发起者。

在历史记录中添加事件

您可以通过添加事件并在其中指定作者来向历史记录中添加事件。此外,您可以指定事件的详细注释。

添加参与时间线的功能

Sacred96\Timeline\Traits\Eventable 特性添加到任何您希望参与时间线历史的模型中。

指示模型是时间线的发起者

添加特性 Sacred96\Timeline\Traits\TimelineInitiator 以指示此模型是时间线的发起者。

如果您想突出时间线的不同方面,这将很有用。比如说,您有一个开始时间线的发票。在这里,他是发起者。其余的演员,如开票公司,将只是时间线中的参与者。

创建时间线历史记录

您可以使用模型数组作为参与者开始时间线历史记录。您还可以设置当前状态。

$history = Timeline::create([$invoiceModel, $userModel, ..., $anotherModel], 'Initial state');

通过 ID 获取时间线历史记录

$history = Timeline::history()->getById($id);

向历史记录中添加新事件

Timeline::event('Event text')
        ->from($eventableModel)
        ->to($history)
        ->withComment('Extended comment to event')
        ->push();

通过 ID 获取事件

Timeline::events()->getByID($id);

获取事件信息

$event->author; // event author

$eventSide = $event->side(); // event side: [initiator_side|second_side]

时间线历史记录的实际状态

$history->switchState('New state text'); // Set timeline actual state

$history->getCurrentState(); // Get timeline actual state

时间线历史记录的附加功能

Timeline::history($history)->getParticipants(); // get all participants of timeline history
Timeline::history($history)->removeParticipants([$participant1, $participant2]); // delete multiple participants
Timeline::history($history)->getEvents('desc'); // get all events of history with sort
Timeline::history($history)->makeFinished(); // make history as finished
Timeline::history($history)->isFinished(); // check if the story is complete

许可证

时间线包是开源软件,许可协议为 MIT 许可证