{"id":19954329,"url":"https://github.com/kimmelsg/cj-temporal-models","last_synced_at":"2025-06-19T12:35:27.908Z","repository":{"id":57024339,"uuid":"71736499","full_name":"kimmelsg/cj-temporal-models","owner":"kimmelsg","description":null,"archived":false,"fork":false,"pushed_at":"2017-11-20T21:56:45.000Z","size":40,"stargazers_count":29,"open_issues_count":0,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-03T19:40:13.457Z","etag":null,"topics":["laravel","laravel-package","php","temporal","temporal-models","temporal-records"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kimmelsg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-23T23:45:13.000Z","updated_at":"2022-01-03T10:43:23.000Z","dependencies_parsed_at":"2022-08-23T13:51:01.262Z","dependency_job_id":null,"html_url":"https://github.com/kimmelsg/cj-temporal-models","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/kimmelsg/cj-temporal-models","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmelsg%2Fcj-temporal-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmelsg%2Fcj-temporal-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmelsg%2Fcj-temporal-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmelsg%2Fcj-temporal-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimmelsg","download_url":"https://codeload.github.com/kimmelsg/cj-temporal-models/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimmelsg%2Fcj-temporal-models/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260752138,"owners_count":23057299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-package","php","temporal","temporal-models","temporal-records"],"created_at":"2024-11-13T01:19:49.441Z","updated_at":"2025-06-19T12:35:22.894Z","avatar_url":"https://github.com/kimmelsg.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Circle CI](https://circleci.com/gh/navjobs/temporal-models.svg?style=shield)](https://circleci.com/gh/navjobs/temporal-models)\n[![Coverage Status](https://coveralls.io/repos/github/navjobs/temporal-models/badge.svg?branch=master)](https://coveralls.io/github/navjobs/temporal-models?branch=master)\n[![Code Climate](https://codeclimate.com/github/navjobs/temporal-models/badges/gpa.svg)](https://codeclimate.com/github/navjobs/temporal-models)\n\n###### Temporal Models for Laravel\nAdds support for Temporal Models to Laravel 5.1+\n\n\u003e Usually in a database, entities are represented by a row in a table, when this row is updated the old information is\n\u003e overwritten. The temporal model allows data to be referenced in time, it makes it possible to query the state of an\n\u003e entity at a given time.\n\u003e\n\u003e For example, say you wanted to keep track of changes to products so when an order is placed you know the state of the\n\u003e product without having to duplicate data in the orders table. You can make the products temporal and use the time of\n\u003e the order to reference the state of the ordered products at that time, rather than how they currently are, as would\n\u003e happen without using temporal data.\n\u003e\n\u003e The temporal model could also be used for auditing changes to things like wiki pages. Any changes would be\n\u003e automatically logged without having to use a separate log table.\n\n[From FuelPHP docs](http://fuelphp.com/dev-docs/packages/orm/model/temporal.html)\n\n## Installation\n\nYou can install this package via Composer using this command:\n\n```bash\ncomposer require navjobs/temporal-models\n```\n\nNext, the model you wish to make temporal must have the following fields in its Schema:\n\n```php\n$table-\u003edateTime('valid_start');\n$table-\u003edateTime('valid_end')-\u003enullable();\n```\n\nThe model itself must use the `Temporal` trait and define two protected properties as in this example:\n\n```php\nclass Commission extends Model\n{\n    use Temporal;\n\n    protected $dates = ['valid_start', 'valid_end'];\n    protected $temporalParentColumn = 'representative_id';\n}\n```\n\nThe $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.\n\n## Usage\n\n###### Creating Temporal Records\nWhen 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.\n\n###### Updating Temporal Records\nIn order to preserve their historic nature, updates to temporal records are restricted to just valid_end after\nthey 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:\n\n```php\nprotected $enableUpdates = true;\n```\n\nAdditionally, the behavior can be changed dynamically by calling ```$model-\u003eenableUpdates()-\u003esave();```\n\n###### Deleting Temporal Records\nTemporal records that have already started cannot be deleted. When the delete method is called on them they will simply\nhave their valid_end set to the current time. If delete is called on a scheduled record then it will succeed.\n\n###### Methods and Scopes\nThe `Temporal` trait includes an isValid() method that optionally takes a Carbon object. The method returns whether the\nmodel was valid on the provided date or now if no Carbon object is provided. Also included are `valid()` and `invalid()`\nscopes. 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.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimmelsg%2Fcj-temporal-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimmelsg%2Fcj-temporal-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimmelsg%2Fcj-temporal-models/lists"}