taam/timeline

使用Laravel轻松创建时间线。原始链接

1.0.3 2022-06-01 13:02 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:50 UTC


README

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

介绍

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

安装

从命令行运行

composer require taam/timeline

发布资源

php artisan vendor:publish

运行迁移

php artisan migrate

用法

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

主要思想

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

创建时间线后,您可以通过指示其作者向历史中添加事件。此外,您还可以为事件指定详细的注释。

历史可能具有实际状态。例如,发起者模型期望用户操作。这可以在时间线的当前状态下表示。当故事结束时,您将时间线标记为完成。

添加参与时间线的功能

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

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

添加特性Taam\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许可证授权。