durjaygp/durjay-views

A unified polymorphic view counter for Laravel models.

Maintainers

Package info

github.com/durjaygp/durjay-views

Language:Blade

pkg:composer/durjaygp/durjay-views

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-05-05 18:45 UTC

This package is auto-updated.

Last update: 2026-05-05 18:56:35 UTC


README

A simple view counter for Laravel. Track views for Blogs, Products, Services, and more in a single table using a helper function or a trait. It also includes an awesome Tailwind-designed dashboard for statistics.

Installation

You can install the package via composer:

composer require durjaygp/durjay-views

Setup

  1. Publish the migration and views (optional):
php artisan vendor:publish --provider="Durjaygp\DurjayViews\DurjayViewsServiceProvider"
  1. Run the migrations:
php artisan migrate

Usage

Using the Helper Function

You can easily track views for any entity using the provided global helper function:

// Parameters: string $type, int $typeId
trackDurjayViews('product', $product->id);
trackDurjayViews('blog', $blog->id);

Using the Trait

Alternatively, you can add the Viewable trait to your models:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Durjaygp\DurjayViews\Traits\Viewable;

class Product extends Model {
    use Viewable;
}

Then you can record a view directly on the model instance:

$product->recordDurjayView();

To get the total view count (sum of all views increments):

echo $product->view_count;

Dashboard Statistics

This package provides a beautifully crafted Tailwind CSS dashboard to visualize your application's views.

You can access the statistics dashboard at: /durjay-views/stats

The dashboard includes:

  • View statistics for Today and Yesterday
  • Total Unique and Today Unique Views metrics
  • A gorgeous 7-day Views Chart
  • A Recent Views Activity table (displays Type, User/Guest, Date, and Total Views)

You can publish the views to customize the design:

php artisan vendor:publish --provider="Durjaygp\DurjayViews\DurjayViewsServiceProvider" --tag="views"