PHPackages                             sinclairt/track - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sinclairt/track

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sinclairt/track
===============

Track changes to your models and any custom events you'd like to keep track of

6.0.12(9y ago)0471MITPHPPHP &gt;=5.4.0

Since Feb 11Pushed 9y agoCompare

[ Source](https://github.com/sinclairt/track)[ Packagist](https://packagist.org/packages/sinclairt/track)[ RSS](/packages/sinclairt-track/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (6)Versions (39)Used By (1)

Installation
============

[](#installation)

`composer require sinclairt/track`

Next you need to register the service provider in app/config/app.php:

```
'Sinclair\Track\TrackServiceProvider'

```

Finally run `php artisan vendor:publish`

Usage
=====

[](#usage)

All you need to do is use the TrackTrait in any model which extends Eloquent that you want tracking.

Note if you include the TrackTrait before running the migrations and seed the database for example the package will fail as the table does not exist to insert data into.

The following events are tracked automatically: Created, Updating, Updated, Deleted, and Restored (This is only tracked when the SoftDeleteTrait is also in use by the model).

This package can track pivot table sync, but an event is not fired inside Laravel so you must implement this manually. This method will only work after calling `sync()`.

After calling this method return the results into the method `trackPivotChanges()` along with the current model and the other fully qualified related model name.

Example:

```
$ids = [1, 2, 3, 4];

$changes = $group->addressees()->sync($ids);

$group->trackPivotChanges($changes, $group, App\Repositories\Addressee\Addressee::class);

```

It is not necessary to use a fully qualified class name however if you want to use the built in presenter then you will, otherwise you can create your own implementation.

### Custom Logging

[](#custom-logging)

You can log anything on an object by calling:

`{object}::log($event, $model = null, $data = [])`

The event is the type of event you are logging, this is where the Track package stores Created/Updated/Deleted etc events. The model will default to the current object if not passed but it is possible to over ride this. The `$data` variable contains all the additional fields you wish to store against the track, they can be :

- user\_id *this will default to the logged in user if available*
- field
- old\_value
- new\_value
- event *although this is the `$event` variable*
- tracked\_type *this will be taken from your supplied model anyway*
- tracked\_id *as above*

### Log Events

[](#log-events)

Add any event class to the events key inside the track config, and the track package will log the event, it will not attach it to any object, but it will be available via the Track model directly.

There is currently a custom example event, you can remove that (or keep if you fancy).

API
===

[](#api)

There are 4 routes into the package:

- *GET* /api/v1/track - get all tracked changes this is paginated
- *POST* /api/v1/track/filter - get a filtered set of tracked changes (paginated). Filters available
    - tracked\_type
    - tracked\_id
    - user\_id
    - event
    - field
    - old\_value
    - new\_value
- *GET* /api/v1/track/{track} - get a single tracked change
- *POST* /api/v1/track/object/ - get all tracked changes by object - this requires the following parameters
    - object\_id
    - object\_class

### API Paginated Calls

[](#api-paginated-calls)

You can set the following parameters for paginated calls:

- rows (integer) *default 15* The number of rows per page
- search (bool) *default true* Whether to use the search function during filter
- orderBy (string) *default null* which column to order the results by
- direction (asc|desc) *default asc* the direction of ordering
- pagination\_name (string) *default page* the name of your paginated set
- columns (array) *default \['\*'\]* which columns to return from the database table

Presenting
==========

[](#presenting)

To get the changes of particular object call the method `trackedChanges()` on your tracked object.

The Track model has a view presenter configured for your benefit.

Example:

```
@foreach($object->trackedChanges as $change)

		{{ $change->present()->prettyChange() }}

@endforeach

```

The following text will be returned:

- "Updated" : User updated the example field from the old value to the new value
- "Attached" : User attached an ExampleObject called Example
- "Detached" : User detached an ExampleObject called Example
- "Default" : User *{created/deleted/restored}* Example with an ID of 1

The presenter uses the Auth User model by default but you can change this in the config file.

The field name used for display is also listed here with username being the default. Equally, when the Presenter is called and it names the attached/detached object it is using the field name of "name" by default. There is no configuration for this as it could be different for each class, in this circumstance you can use the Presenter as a template and create your own, or ensure your tables that have pivots have a name field on them.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Total

38

Last Release

3335d ago

Major Versions

1.1 → 4.02015-03-27

4.0 → 5.02015-03-27

4.1 → 5.12015-06-19

5.1.21 → 6.0.02016-09-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/a0dc010eef4e76d1eb705b4f2257422302ada2164add753976f7998d9203b19a?d=identicon)[sinclairt](/maintainers/sinclairt)

---

Top Contributors

[![sinclairt](https://avatars.githubusercontent.com/u/16877448?v=4)](https://github.com/sinclairt "sinclairt (18 commits)")[![tom-sinclair](https://avatars.githubusercontent.com/u/23167798?v=4)](https://github.com/tom-sinclair "tom-sinclair (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sinclairt-track/health.svg)

```
[![Health](https://phpackages.com/badges/sinclairt-track/health.svg)](https://phpackages.com/packages/sinclairt-track)
```

###  Alternatives

[selective/basepath

A URL base path detector for Slim 4

50521.0k12](/packages/selective-basepath)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
