<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
therealedatta / fork-cyrildewit-eloquent-viewable-tags example snippets
// Get the total number of views
$post->getViews();
// Get the total number of views since the given date
$post->getViews(Period::since(Carbon::parse('2014-02-23 00:00:00')));
// Get the total number of views between the given date range
$post->getViews(Period::create(Carbon::parse('2014-00-00 00:00:00'), Carbon::parse('2016-00-00 00:00:00')));
// Get the total number of views in the past 6 weeks (from today)
$post->getViews(Period::pastWeeks(6));
// Get the total number of views in the past 2 hours (from now)
$post->getViews(Period::subHours(2));
// Store a new view in the database
$post->addView();
/**
* Get the total number of views.
*
* @param \CyrildeWit\EloquentViewable\Support\Period
* @return int
*/
public function getViews($period = null): int;
/**
* Get the total number of unique views.
*
* @param \CyrildeWit\EloquentViewable\Support\Period
* @return int
*/
public function getUniqueViews($period = null) : int;
// Create a new Period instance.
Period::create(DateTime $startDateTime = null, DateTime $endDateTime = null);
// Create a new Period instance with only a start date time.
Period::since(DateTime $startDateTime);
// Create a new Period instance with only a end date time.
Period::upto(DateTime $endDateTime);
// Period instance with a start date time of today minus the given days.
Period::pastDays(int $days);
// Period instance with a start date time of today minus the given weeks.
Period::pastWeeks(int $weeks);
// Period instance with a start date time of today minus the given months.
Period::pastMonths(int $months);
// Period instance with a start date time of today minus the given years.
Period::pastYears(int $years);
// Period instance with a start date time of now minus the given seconds.
Period::subSeconds(int $seconds);
//Period instance with a start date time of now minus the given minutes.
Period::subMinutes(int $minutes);
// Period instance with a start date time of now minus the given hours.
Period::subHours(int $hours);
// Period instance with a start date time of now minus the given days.
Period::subDays(int $days);
// Period instance with a start date time of now minus the given weeks.
Period::subWeeks(int $weeks);
// Period instance with a start date time of now minus the given months.
Period::subMonths(int $months);
// Period instance with a start date time of now minus the given years.
Period::subYears(int $years);
use CyrildeWit\EloquentViewable\Views;
Views::create($post)->getViews();
use CyrildeWit\EloquentViewable\Views;
Views::getViewsByType($post);
Views::getViewsByType(Post::class);
Views::getViewsByType('App\Post');
use CyrildeWit\EloquentViewable\Views;
// Get top 10 most viewed by type
Views::getMostViewedByType($post, 10);
Views::getMostViewedByType(Post::class, 10);
Views::getMostViewedByType('App\Post', 10);
// Get top 10 lowest viewed by type
Views::getLowestViewedByType($post, 10);
Views::getLowestViewedByType(Post::class, 10);
Views::getLowestViewedByType('App\Post', 10);
use CyrildeWit\EloquentViewable\Views;
Views::getViewsPerPeriod('minute', 30); // per 30 minutes
Views::getViewsPerPeriod('hour', 12); // per 12 hours
Views::getViewsPerPeriod('day'); // per day
Views::getViewsPerPeriod('week', 2); // per 2 weeks
Views::getViewsPerPeriod('month'); // per month
Views::getViewsPerPeriod('year'); // per month
// ...
public function getViewsSince(DateTime $sinceDateTime)
{
return $this->getViews(Period::since($sinceDateTime));
}
public function getViewsUpto(DateTime $uptoDateTime)
{
return $this->getViews(Period::upto($uptoDateTime));
}
public function getViewsBetween(DateTime $sinceDateTime, DateTime $uptoDateTime)
{
return $this->getViews(Period::create($sinceDateTime, $uptoDateTime));
}
public function getViewsInPastDays(int $days)
{
return $this->getViews(Period::pastDays($days));
}
// ...