combindma/laravel-popularity
Composer 安装命令:
composer require combindma/laravel-popularity
包简介
A Laravel package for tracking popular entries(by Models) of a website in a certain time
README 文档
README
With Laravel Popularity Package you can Track your most popular Eloquent Models based on unique hits in a time range and then sort by popularity in a time frame.With Laravel Popular Package you can Track your most popular Eloquent Models based on unique hits in a time range and then sort by popularity in a time frame.
Installation
You can install the package via composer:
composer require combindma/laravel-popularity
You can publish and run the migrations with:
php artisan vendor:publish --tag="popularity-migrations"
php artisan migrate
Usage
Use the visitable trait on the model you intend to track
use Combindma\Popularity\Traits\Visitable; class Page extends Model { use Visitable; ... }
This is how you create a visit (visits are not duplicated for a daily timeframe):
// Adding a visit to the page. $page->visit(); // Adding a visit to the page with ip address. $page->visit()->withIp(); // Adding a visit with the given ip address. $page->visit()->withIp('my-ip-address'); // Adding a visit with custom data. $page->visit()->withData(['item' => 'value']); // Adding a visit with logged user. $page->visit()->withUser(); // Adding a visit with the given user. $page->visit()->withUser($userId); // Adding a visit with all above methods. $page->visit()->withIp()->withUser()->withData(['item' => 'value']);
Changing the timeframe for creating visits with the same data:
// creates visits after hourly timeframe $page->hourlyInterval()->withIp(); // creates visits after a daily timeframe $page->dailyInterval()->withIp(); // creates visits after a weekly timeframe $page->weeklyInterval()->withIp(); // creates visits after a monthly timeframe $page->monthlyInterval()->withIp();
Getting the records by the most visited
// gets the total visit count $page = Page::withTotalVisitCount()->first(); return $page->visit_count_total; // gets records by all time popularity $pages = Page::popularAlltime()->get(); return $pages->first()->visit_count_total; // gets popular records between two dates $pages = Page::popularBetween(Carbon::createFromDate(1990, 12, 01), Carbon::createFromDate(1990, 12, 04))->get(); return $pages->first()->visit_count; // gets popular records by the last x days $pages = Page::popularLastDays(2)->get(); retutn $pages->first()->visit_count; // gets popular records by the last week $pages = Page::popularLastWeek()->get(); return $pages->first()->visit_count; // gets popular records by this week $pages = Page::popularThisWeek()->get(); return $pages->first()->visit_count; // gets popular records by the last month $pages = Page::popularLastMonth()->get(); return $pages->first()->visit_count; // gets popular records by this month $pages = Page::popularThisMonth()->get(); return $pages->first()->visit_count; // gets popular records by this year $pages = Page::popularThisYear()->get(); return $pages->first()->visit_count;
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
combindma/laravel-popularity 适用场景与选型建议
combindma/laravel-popularity 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 258 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「combindma」 「laravel-popularity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 combindma/laravel-popularity 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 combindma/laravel-popularity 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 combindma/laravel-popularity 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Meta pixel integration for Laravel
A package to track the popularity of your Laravel models.
Laravel package to communicate with the CMI payment plateform
A simple package for tracking user activities on your Laravel website.
Laravel Twillio SMS API Integration
A key-value storage for laravel
统计信息
- 总下载量: 258
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-22