rezaamini-ir/laravel-tracker

Track your data in project

1.0.1 2022-01-29 19:34 UTC

This package is auto-updated.

Last update: 2024-10-29 00:31:53 UTC


README

A package to track your model data and monitor model data

Installation

First you should install package with composer :

composer require rezaamini-ir/laravel-tracker

Next publish dependencies :

php artisan tracker:install

Now you can run migration to create tracker tables:

php artisan migrate

There we go, We have installed package, Let's use it.

Usage

To use from package you must use from tracker trait in model which you want to track

use Tracker\Traits\Trackable;

class Article extends Model{
    use Trackable;
}

Now you can use track() method to track in your Article Single page controller

class ArticleContoller extends Controller
{
    public function show(Article $article){
        $article->track();
        //..
    }
}

It will be tracked after every seen by users. You can set track_mode in config in choose what kind of tracker should be used in your project.

In your stats page you can use tracks() and trackCount() method to get tracked data. For example :

class StatsContoller extends Controller
{
    public function getStats(Article $article){
        $article->trackCount(); // An integer of tracked count
        $article->tracks; // A collection of tracked data 
        $article->trackBetween(now()->subDays(7), now()); // Tracked data between range of date since last week 
    }
}