luqta/viewcount

该包使您能够计算资源的查看次数

v2.0 2020-02-16 12:15 UTC

This package is auto-updated.

Last update: 2024-09-16 22:35:44 UTC


README

该包使您能够计算资源(MongoDB 集合)的查看次数

安装

  1. 通过 Composer
$ composer require luqta/viewcount
  1. 验证 vistor_ip
'user_id' => 'string',
'countable' => 'required|boolean',
'vistor_ip' => 'required_if:countable,1|string',
'user_agent' => 'required_if:countable,1|string',
'browser_language' => 'required_if:countable,1|string',
'screen.width' => 'required_if:countable,1|numeric',
'screen.height' => 'required_if:countable,1|numeric',
'inner.width' => 'required_if:countable,1|numeric',
'inner.height' => 'required_if:countable,1|numeric',
  1. view_count 字段添加到您的资源集合中。
protected $fillable = [
    ...
    'view_count',
    ...
];
  1. 在您的资源控制器中调度 Luqta\ViewCount\ViewCountJob 任务。
dispatch(new ViewCountJob($model, $request->validated()));
  1. 在您的资源模型中使用 Luqta\ViewCount\Traits\Countable 特性。