durjaygp/durjay-views
Composer 安装命令:
composer require durjaygp/durjay-views
包简介
A unified polymorphic view counter for Laravel models.
README 文档
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
- Publish the migration and views (optional):
php artisan vendor:publish --provider="Durjaygp\DurjayViews\DurjayViewsServiceProvider"
- 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"
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.
durjaygp/durjay-views 适用场景与选型建议
durjaygp/durjay-views 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 durjaygp/durjay-views 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 durjaygp/durjay-views 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-05
