PHPackages                             phpcollective/tracker - 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. [Database &amp; ORM](/categories/database)
4. /
5. phpcollective/tracker

ActiveLibrary[Database &amp; ORM](/categories/database)

phpcollective/tracker
=====================

Track your Elequent Model

v1.0.3(2y ago)31331MITPHPPHP &gt;=7.1.3CI failing

Since Apr 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/phpcollective/tracker)[ Packagist](https://packagist.org/packages/phpcollective/tracker)[ RSS](/packages/phpcollective-tracker/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (3)Dependencies (2)Versions (7)Used By (0)

Laravel Model Tracker
---------------------

[](#laravel-model-tracker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f5f3c9ea7edde96d130a806662231e794ff7589c09f2321eb2ea8897cb3f3b84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706870636f6c6c6563746976652f747261636b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpcollective/tracker)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/fc71b54d8701f95651b21ed7e9d53d229cec939e62c1ae5bf5067ca31107c392/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706870636f6c6c6563746976652f747261636b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpcollective/tracker)

By default, Eloquent automatically manage `created_at` and `updated_at` columns to exist on your tables. In addition to this it also manage a `deleted_at` attribute if the model use "soft delete". However it is very tedious job to manage who create/update the model as well as delete (if soft delete). This also a indication of code repetition.

If you wish to have these automatically managed by Eloquent, `Tracker` is a nice and convenient way to do this.

Install
-------

[](#install)

You may use Composer to install the package into your Laravel project:

```
composer require phpcollective/tracker
```

##### Laravel 5.5+:

[](#laravel-55)

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

```
PhpCollective\Tracker\TrackingServiceProvider::class,
```

Database: Migrations
--------------------

[](#database-migrations)

To add `created_by` and `updated_by` columns in your table you want to track just use `$table->track()` method in your table migration file. For dropping the columns use `$table->dropTrack()`.

```
Schema::create('table', function (Blueprint $table) {
    ...
    $table->track();
});

// To drop columns
Schema::table('table', function (Blueprint $table) {
    $table->dropTrack();
});
```

If Your table contains `soft delete` columns, just pass `boolean` `true` in the method. It will add a `deleted_by` column in database.

```
Schema::create('table', function (Blueprint $table) {
    ...
    $table->softDeletes();
    $table->track(true);
});

// To drop columns with soft delete
Schema::table('table', function (Blueprint $table) {
    $table->dropTrack(true);
});
```

Model
-----

[](#model)

Add `Trackable` trait in model you want to track. Now it will handle all `CRUD` event by the authenticate user.

```
