luqta/viewcount

The package enables you to calculate the view count of a resource

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

This package is auto-updated.

Last update: 2024-04-16 21:45:50 UTC


README

The package enables you to calculate the view count of a resource (MongoDB Collection).

Installation

  1. Via Composer
$ composer require luqta/viewcount
  1. Validate 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. Add view_count field to your resource collection.
protected $fillable = [
    ...
    'view_count',
    ...
];
  1. Dispatch Luqta\ViewCount\ViewCountJob job in your resource controller.
dispatch(new ViewCountJob($model, $request->validated()));
  1. Use Luqta\ViewCount\Traits\Countable trait in your resource model.