durjaygp/durjay-views 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

durjaygp/durjay-views

最新稳定版本:1.1

Composer 安装命令:

composer require durjaygp/durjay-views

包简介

A unified polymorphic view counter for Laravel models.

README 文档

README

Durjay Views

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.

Views Dashboard

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"

Admin Route (Protected Access)

By default the dashboard is accessible at /durjay-views/stats. If you want to protect it behind authentication or admin middleware, publish the config and set your preferred middleware:

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

Then update config/durjay-views.php:

return [
    /*
    |--------------------------------------------------------------------------
    | Dashboard Middleware
    |--------------------------------------------------------------------------
    | Middleware applied to the /durjay-views/stats route.
    | Use 'auth' to restrict to logged-in users, or 'auth,admin' for admins.
    |
    */
    'middleware' => ['web', 'auth'],
];

The route is registered automatically — no extra steps needed after changing the config.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固