{"id":15067093,"url":"https://github.com/tpenaranda/model-log","last_synced_at":"2025-04-10T16:42:37.794Z","repository":{"id":57072265,"uuid":"116151632","full_name":"tpenaranda/model-log","owner":"tpenaranda","description":"A Laravel 5 package to log attributes changes of any of your app models.","archived":false,"fork":false,"pushed_at":"2020-09-01T04:13:32.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T14:38:57.618Z","etag":null,"topics":["attributes","changes","composer","eloquent","laravel","laravel-5-package","laravel5","logger","logging","model","tate","track"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tpenaranda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-03T15:21:54.000Z","updated_at":"2022-10-28T04:48:48.000Z","dependencies_parsed_at":"2022-08-24T14:54:34.350Z","dependency_job_id":null,"html_url":"https://github.com/tpenaranda/model-log","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpenaranda%2Fmodel-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpenaranda%2Fmodel-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpenaranda%2Fmodel-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpenaranda%2Fmodel-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpenaranda","download_url":"https://codeload.github.com/tpenaranda/model-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248252728,"owners_count":21072703,"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":["attributes","changes","composer","eloquent","laravel","laravel-5-package","laravel5","logger","logging","model","tate","track"],"created_at":"2024-09-25T01:16:24.213Z","updated_at":"2025-04-10T16:42:37.776Z","avatar_url":"https://github.com/tpenaranda.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel ModelLog\n\n[![Latest Stable Version](https://poser.pugx.org/tpenaranda/model-log/v/stable)](https://packagist.org/packages/tpenaranda/model-log) [![Total Downloads](https://poser.pugx.org/tpenaranda/model-log/downloads)](https://packagist.org/packages/tpenaranda/model-log) [![License](https://poser.pugx.org/tpenaranda/model-log/license)](https://packagist.org/packages/tpenaranda/model-log)\n\nA Laravel package to automatically log attributes changes on any of your app models.\n\n## About package\nThis package is intended for tracking changes of your Eloquent models inside your Laravel application.\nA new DB table will be created and everytime a model attribute is updated an entry will be automatically created on the DB log table.\n\n## Installation\n\nInstall package using [Composer](http://getcomposer.org).\n\n    $ composer require tpenaranda/model-log\n\nRun migrations to create ModelLog table.\n\n    $ php artisan migrate\n\n## [This step is not needed on Laravel \u003e= 5.5] Add service provider and create ModelLog DB table.\n\nAdd service provider and alias in config/app.php\n\n```\n    'providers' =\u003e [\n        ...\n        TPenaranda\\ModelLog\\Providers\\ModelLogServiceProvider::class,\n    ],\n    'aliases' =\u003e [\n        ...\n        'ModelLogEntry' =\u003e TPenaranda\\ModelLog\\ModelLogEntry::class,\n        'ObservedByModelLog' =\u003e TPenaranda\\ModelLog\\Traits\\ObservedByModelLog::class,\n    ],\n\n```\n\nRun  ModelLog command in order to create ModelLog DB table.\n\n    $ php artisan model-log:create-log-table\n\n## Usage\n\nAdd 'ObservedByModelLog' trait to your model and specify attributes you want to observe/track for changes.\n\n```\nuse TPenaranda\\ModelLog\\Traits\\ObservedByModelLog;\n\nclass MyModel extends Model\n{\n    use ObservedByModelLog;\n\n    protected $log = ['my_attribute', 'track_this_column_too'];\n}\n```\n\nNow after every update on that model, observed attributes will be logged automatically.\nUse `protected $log = 'all';` (notice the string, not array) to log any change.\n\nRetrieve log entries:\n\n```\n$my_model-\u003elogEntries;\n```\n\n## Advanced usage\n\nRetrieve log entries using query scopes:\n\n```\n\\ModelLogEntry::whereModelClass('App\\MyModel')-\u003ewhereAttribute('my_attribute')-\u003ewhereTo('value_after_change')-\u003eget();\n```\n\nAvailable scopes:\n\n- whereModel(`\u003cobject\u003e`): _Get logs of an specific Eloquent Model_ (example: get log data of MyModel ID #4).\n- whereModelClass(`\u003cstring/object\u003e`): _Get logs for an specific model class_ (example: get entries where MyModel class is involved, regardless of any IDs).\n- whereAttribute(`\u003cstring\u003e`): _Get only logs where some specific attribute was changed._\n- whereFrom(`\u003cstring\u003e`): _Get only logs with an specific initial value._\n- whereTo(`\u003cstring\u003e`): _Get only logs with an specific end value._\n- ModifiedByUser(`\u003cnumeric/object\u003e`): _Get changes done by some specific user._ Allowed parameters: null, numeric IDs or User object.\n\nThe following scopes only accept [Carbon](http://carbon.nesbot.com) objects as parameters:\n- loggedBefore(`\u003cCarbon object\u003e`): _Retrieve only entries logged prior to specific date._\n- loggedAfter(`\u003cCarbon object\u003e`): _Retrieve only entries logged after specific date._\n- withinDateRange(`\u003cCarbon object\u003e`, `\u003cCarbon object\u003e`): _Retrieve only entries logged after first parameter and prior to second parameter._\n\nCreate (or drop and create) ModelLog table manually:\n\n    $ php artisan model-log:create-log-table\n\nFlush ModelLog table:\n\n```\n\\ModelLogEntry::flushAll();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpenaranda%2Fmodel-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpenaranda%2Fmodel-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpenaranda%2Fmodel-log/lists"}