District Core Developer DocsDistrict Core Developer Docs
Developers
Boilerplate
Modules
Bitbucket
Developers
Boilerplate
Modules
Bitbucket
  • Modules

    • ABN
    • ActivityLog
    • AnalyticsApi
    • ApiConnector
    • BlockApi
    • CategoryApi
    • CloneApi
    • CommentApi
    • ContentApi
    • Core
    • Documents
    • EmbedApi
    • Event
    • ExportApi
    • FeatureApi
    • FormApi
    • GTM
    • GalleryApi
    • HelpApi
    • Hotspot
    • IdeaSurvey
    • ImportApi
    • InteractionsApi
    • Intercom
    • MailApi
    • MapApi
    • MapSurvey
    • MediaApi
    • MenuApi
    • MetaTagApi
    • NlpApi
    • NotificationApi
    • Page
    • ParentableContent
    • PaymentApi
    • PermissionsApi
    • Postcode
    • ReCaptcha
    • Redirects
    • Renderer
    • ReportApi
    • RestrictionApi
    • RevisionApi
    • SearchApi
    • Settings
    • ShareableApi
    • Slack
    • SlugApi
    • SubscribableApi
    • Survey
    • Team
    • TenantApi
    • TestApi
    • ThemeApi
    • Timeline
    • TranslationApi
    • Update
    • Users
    • VisualisationApi
    • WorkflowApi
    • Wysiwyg

RevisionAPI module

This package provides a trait which can be used to add version tracking functionality to an entity.

It uses mpociot/versionable under the hood, but you can use the trait (and interface) provided by this module directly.

Example

use Modules\RevisionApi\Traits\HasRevisionsTrait;
use Illuminate\Database\Eloquent\Model;

class ModelClass extends Model implements HasRevisionsInterface
{
    use HasRevisionsTrait;

    // You can now get the version history with $example->versions();
    
    // You can get the previous version with $example->previousVersion();
    
    // You can compare older versions with the current version $example->previousVersion()->diff()

    // You can compare specific versions with $example->versions->get(4)->diff($example->versions->get(2))

    // You can hide fields from versioning by setting the property
    // protected $hidden = ['email', 'password'];

    // You can prevent an update from creating a version
    // $example->disableVersioning();
    
    // You can revert to a previous version with $example->previousVersion()->revert();

    // Your Model should include a 'status' attribute (short int) which will be saved with the versions.

    // You can query Model by status:
    // M$results = odel::withStatus(2);

    // Or versions by status:
    // $results = Model::versionsWithStatus(2);

    // You can listen for status changes with the StatusChangeRevisionEvent event.
}

Edit this page
Prev
RestrictionApi
Next
SearchApi