All Projects → kimmelsg → cj-temporal-models

kimmelsg / cj-temporal-models

Licence: MIT license
No description or website provided.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to cj-temporal-models

laravel-temporal
Temporal models and versioning for Laravel
Stars: ✭ 19 (-34.48%)
Mutual labels:  temporal, temporal-models
laravel-ovh
Wrapper for OVH Object Storage integration with laravel
Stars: ✭ 30 (+3.45%)
Mutual labels:  laravel-package
laravel-json-api
Integrate JSON:API resources on Laravel
Stars: ✭ 17 (-41.38%)
Mutual labels:  laravel-package
response
Response HTTP package for Simfony, Laravel, Lumen and PHP 7 with standard REST API
Stars: ✭ 14 (-51.72%)
Mutual labels:  laravel-package
qqmap-region
腾讯位置服务中国标准行政区划数据 SDK
Stars: ✭ 22 (-24.14%)
Mutual labels:  laravel-package
canvas
Code Generators for Laravel Applications and Packages
Stars: ✭ 139 (+379.31%)
Mutual labels:  laravel-package
Laravel-Crud-Generator
A Simple Laravel Library that allows to create crud operation with a single command
Stars: ✭ 20 (-31.03%)
Mutual labels:  laravel-package
LaraPersonate
Login as a different user quickly
Stars: ✭ 121 (+317.24%)
Mutual labels:  laravel-package
lost-in-translation
Uncover missing translations and localization strings in Laravel applications.
Stars: ✭ 32 (+10.34%)
Mutual labels:  laravel-package
laravel-error-handler
Laravel 5.2/5.3 package for better exception handling.
Stars: ✭ 15 (-48.28%)
Mutual labels:  laravel-package
tall-toasts
A Toast notification library for the Laravel TALL stack. You can push notifications from the backend or frontend to render customizable toasts with almost zero footprint on the published CSS/JS 🔥🚀
Stars: ✭ 296 (+920.69%)
Mutual labels:  laravel-package
laravel-twig
Twig for Laravel Framework
Stars: ✭ 16 (-44.83%)
Mutual labels:  laravel-package
laravel-vatvalidator
Package to validate a vat id via the api of the european union (vies)
Stars: ✭ 15 (-48.28%)
Mutual labels:  laravel-package
laravel-php-k8s
Just a simple port of renoki-co/php-k8s for easier access in Laravel
Stars: ✭ 71 (+144.83%)
Mutual labels:  laravel-package
s3x
s3x is a minio gateway providing an S3 API powered by TemporalX that uses IPFS as the data storage layer. It lets you turn any S3 application into an IPFS application with no change in application design
Stars: ✭ 85 (+193.1%)
Mutual labels:  temporal
laravel-package
Laravel package template
Stars: ✭ 31 (+6.9%)
Mutual labels:  laravel-package
query-filter
Define filters for your Eloquent models based on your request
Stars: ✭ 20 (-31.03%)
Mutual labels:  laravel-package
laravel-crm
Free & Opensource Laravel CRM solution for SMEs and Enterprises for complete customer lifecycle management.
Stars: ✭ 927 (+3096.55%)
Mutual labels:  laravel-package
laravel-viva-payments
A Laravel package for integrating the Viva Payments gateway
Stars: ✭ 29 (+0%)
Mutual labels:  laravel-package
laravel-sri
Subresource Integrity (SRI) package for Laravel
Stars: ✭ 24 (-17.24%)
Mutual labels:  laravel-package

Circle CI Coverage Status Code Climate

Temporal Models for Laravel

Adds support for Temporal Models to Laravel 5.1+

Usually in a database, entities are represented by a row in a table, when this row is updated the old information is overwritten. The temporal model allows data to be referenced in time, it makes it possible to query the state of an entity at a given time.

For example, say you wanted to keep track of changes to products so when an order is placed you know the state of the product without having to duplicate data in the orders table. You can make the products temporal and use the time of the order to reference the state of the ordered products at that time, rather than how they currently are, as would happen without using temporal data.

The temporal model could also be used for auditing changes to things like wiki pages. Any changes would be automatically logged without having to use a separate log table.

From FuelPHP docs

Installation

You can install this package via Composer using this command:

composer require navjobs/temporal-models

Next, the model you wish to make temporal must have the following fields in its Schema:

$table->dateTime('valid_start');
$table->dateTime('valid_end')->nullable();

The model itself must use the Temporal trait and define two protected properties as in this example:

class Commission extends Model
{
    use Temporal;

    protected $dates = ['valid_start', 'valid_end'];
    protected $temporalParentColumn = 'representative_id';
}

The $temporalParentColumn property contains the name of the column tying the temporal records together. In the example above the model would represent a commission rate. Its $temporalParentColumn might be 'representative_id'. A representative/salesperson would have only one active commission rate at any given time. Representing the commission in a temporal fashion enables us to record history of the commission rate and schedule any future commission rates.

Usage

Creating Temporal Records

When a temporal record is created it automatically resolves any scheduling conflicts. If a newly created record overlaps with a previously scheduled record then the previously scheduled record will be deleted. Any records already started will have their valid_end set to the valid_start of the newly created record. Temporal records cannot be created in the past.

Updating Temporal Records

In order to preserve their historic nature, updates to temporal records are restricted to just valid_end after they have started. Attempts to update any other fields will fail. If this behavior is undesirable, it can be modified by adding the following property to the temporal model:

protected $enableUpdates = true;

Additionally, the behavior can be changed dynamically by calling $model->enableUpdates()->save();

Deleting Temporal Records

Temporal records that have already started cannot be deleted. When the delete method is called on them they will simply have their valid_end set to the current time. If delete is called on a scheduled record then it will succeed.

Methods and Scopes

The Temporal trait includes an isValid() method that optionally takes a Carbon object. The method returns whether the model was valid on the provided date or now if no Carbon object is provided. Also included are valid() and invalid() scopes. These scopes query for either the valid or invalid scopes at the time of the passed Carbon object or now if no Carbon object is passed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].