承接 iotronlab/laravel-page-view 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

iotronlab/laravel-page-view

最新稳定版本:v1.1.0

Composer 安装命令:

composer require iotronlab/laravel-page-view

包简介

Laravel Model Client View Counting Made Easy

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

A simple package to track page views for any Laravel Eloquent model. It stores view records with IP, session, and user agent information to prevent duplicate counting.

Installation

composer require iotronlab/laravel-page-view

Publish and run the migrations:

php artisan vendor:publish --tag="laravel-page-view-migrations"
php artisan migrate

Optionally publish the config file:

php artisan vendor:publish --tag="laravel-page-view-config"

Configuration

use Iotronlab\LaravelPageView\LaravelPageView;

return [
    // Auto-prune old page view records
    'range' => [
        'type' => LaravelPageView::MONTH, // or LaravelPageView::YEAR
        'value' => 1
    ],
];

Usage

1. Add the trait to your model

use Iotronlab\LaravelPageView\Traits\hasPageView;

class Post extends Model
{
    use hasPageView;
}

2. Add a views column to your model's table

$table->unsignedBigInteger('views')->default(0);

3. Record page views

// In your controller
public function show(Request $request, Post $post)
{
    $post->hasPageViews($request);

    return view('posts.show', compact('post'));
}

4. Access view data

// Get the view count
$post->views;

// Get formatted views (1K, 1.5M, etc.)
$post->formatted_views;

// Get all page view records
$post->pageViews;

Generate fake views for testing

$post->fakePageViews();        // Creates a view in the past 30 days
$post->fakePageViews(true);    // Creates a view in the next 30 days

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-08