DEV Community

Cover image for Durjay Views A Simple Laravel View Counter Package
Durjay Ghosh
Durjay Ghosh

Posted on

Durjay Views A Simple Laravel View Counter Package

Introducing Durjay Views — A Simple Laravel View Counter Package

Tracking views in a Laravel application should be simple, flexible, and developer-friendly. That’s why I built Durjay Views — a lightweight Laravel package for counting views on blogs, products, services, or any model with minimal setup.

GitHub Repository:
https://github.com/durjaygp/durjay-views

✨ Features

  • Simple Laravel view tracking
  • Track views using a helper function
  • Trait-based model integration
  • Supports Blogs, Products, Services, and custom entities
  • Stores everything in a single database table
  • Tailwind CSS statistics dashboard
  • Unique visitor tracking
  • 7-day views chart
  • Recent activity table
  • Easy customization

📦 Installation

Install the package via Composer:

composer require durjaygp/durjay-views
Enter fullscreen mode Exit fullscreen mode


`

Publish migrations and views:

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

Run migrations:

bash
php artisan migrate


🚀 Usage

Option 1: Using the Helper Function

You can track views instantly using a simple helper:

`php
trackDurjayViews('product', $product->id);

trackDurjayViews('blog', $blog->id);
`


Option 2: Using the Viewable Trait

If you prefer a cleaner model-based approach, use the included trait:

`php
namespace App\Models;

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

class Product extends Model
{
use Viewable;
}
`

Now record views directly:

php
$product->recordDurjayView();

Get total views:

php
echo $product->view_count;


📊 Beautiful Statistics Dashboard

Visit:

bash
/durjay-views/stats

The dashboard includes:

  • Today vs Yesterday statistics
  • Total unique visitors
  • Today's unique visitors
  • 7-day interactive views chart
  • Recent activity tracking
  • Guest/User detection

You can also publish and customize the dashboard views:

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


💡 Why I Built This

Most view counter solutions I found were either:

  • Too complicated
  • Required multiple tables
  • Lacked dashboards
  • Were difficult to integrate

So I decided to create something:

  • Beginner-friendly
  • Lightweight
  • Modern-looking
  • Easy to extend

🛠 Perfect For

  • Blog platforms
  • eCommerce stores
  • Portfolio websites
  • SaaS applications
  • CMS systems
  • Admin dashboards

⭐ GitHub Repository

👉 https://github.com/durjaygp/durjay-views

Feedback, issues, and contributions are always welcome.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.