定制 balajidharma/laravel-viewable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

balajidharma/laravel-viewable

最新稳定版本:v2.0.1

Composer 安装命令:

composer require balajidharma/laravel-viewable

包简介

Track Page views for your Laravel projects

README 文档

README

Track Page views for your Laravel projects.

Total Downloads Latest Stable Version License

Credits

This package builds upon the work done in cyrildewit/eloquent-viewable and has been modified to suit specific needs. We are grateful to the original author and contributors for their work.

Features

  • Track page views for Laravel Eloquent models
  • Configure unique views by IP, session, and authenticated users
  • Bot detection and filtering
  • Support for DNT (Do Not Track) header
  • Configurable view counting and storage

Table of Contents

Installation

  • Install the package via composer
composer require balajidharma/laravel-viewable
  • Publish the migration with
php artisan vendor:publish --provider="BalajiDharma\LaravelViewable\ViewableServiceProvider" --tag="migrations"
  • Run the migration
php artisan migrate
  • To Publish the config/viewable.php config file with
php artisan vendor:publish --provider="BalajiDharma\LaravelViewable\ViewableServiceProvider" --tag="config"
  • Preparing your model To associate views with a model, the model must implement the HasViewable trait:
<?php
namespace BalajiDharma\LaravelForum\Models;

use BalajiDharma\LaravelViewable\Traits\HasViewable;
use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    use HasViewable;
	
  • Recording views To make a view record, you can call the record method.
public function show(Thread $thread)
{
    $thread->record();
    

Laravel Viewable Configuration

This document describes all configuration options available in the viewable.php config file.

Configuration Options

Models

'models' => [
    'viewable' => BalajiDharma\LaravelViewable\Models\Viewable::class,
],

Defines the model class used for tracking views. You can override this with your own model class if needed.

'table_names' => [
    'viewable' => 'views',
],

Specifies the database table name used for storing views. Default is 'views'.

Bot Detection

'ignore_bots' => true,
  • true: Ignores views from bots and crawlers
  • false: Records views from all visitors including bots
  • Default: true

Do Not Track (DNT) Header

'honor_dnt' => false,
  • true: Respects the Do Not Track (DNT) header from browsers
  • false: Records views regardless of DNT header
  • Default: false

Unique View Settings

'unique_ip' => true,
'unique_session' => true,
'unique_viewer' => true,

Controls how unique views are tracked:

  • unique_ip: Records only one view per IP address
  • unique_session: Records only one view per session
  • unique_viewer: Records only one view per authenticated user
  • Default: All set to true

Model View Counter

'increment_model_view_count' => false,
'increment_model_column_name' => 'view_count',
  • increment_model_view_count: Enable/disable automatic view count increment on the model
  • increment_model_column_name: Specifies the column name for storing view count
  • Default: Counter disabled, column name set to 'view_count'

IP Address Filtering

'ignored_ip_addresses' => [
    //'127.0.0.1',
],
  • Array of IP addresses to ignore when recording views
  • Views from these IPs will not be recorded
  • Default: Empty array (no IPs ignored)

Control configuration on model

You able to control all the configurtion on model, by adding below properties

<?php
namespace BalajiDharma\LaravelForum\Models;

use BalajiDharma\LaravelViewable\Traits\HasViewable;
use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    use HasViewable;

    protected $ignore_bots = true;

    protected $honor_dnt = true;

    protected $unique_session = false;

    protected $unique_ip = false;

    protected $unique_viewer = false;

    protected $increment_model_view_count = true;

    protected $increment_model_column_name = 'view_count';

    protected $ignored_ip_addresses = [
        '127.0.0.1',
        '0.0.0.0'
    ]

Demo

The "Basic Laravel Admin Penel" starter kit come with Laravel Viewable

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固