ExA2040 / laravel-view-counter by ExA2040

A view and like counter extension for your laravel project.
17
0
1
Package Data
Maintainer Username: ExA2040
Maintainer Contact: Ehsan_Alinezhad@ymail.com (Ehsan Alinezhad)
Package Create Date: 2016-12-01
Package Last Update: 2017-01-26
Language: PHP
License: MIT
Last Refreshed: 2024-12-11 15:15:29
Package Statistics
Total Downloads: 17
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Laravel ViewCounter

A view and like counter extension for your laravel project. It uses session storage if the user is not logged in and keeps it clean while the session is active (no double likes or views). If a user is logged in, the information about hthe likes and views are stored into the database for getting history.

Installation

Install using composer:

composer require exa2040/view-counter

While the package is not stable, please make sure you added it as dev: Open "composer.json" manually and add "fraank/view-counter": "dev-master" into require.

Add the service provider in app/config/app.php:

ExA2040\LaravelViewCounter\ViewCounterServiceProvider::class,

The service provider will register an interface for your models to use view_counter and like_couter functionality.

To create the basic tables you have to provide the migation files:

php artisan vendor:publish

Now you can migrate:

php artisan migrate

Now you can register the like and view functionality in your model:

class Object extends Eloquent {
  use ExA2040\LaravelViewCounter\ViewCounterTrait;
}

You can call the actions for like and unlike in your views (or controllers) like this:

{{ route('view_counter.like', array('class_name' => 'post', 'object_id' => $post->id)) }}
{{ route('view_counter.unlike', array('class_name' => 'post', 'object_id' => $post->id)) }}

Examples

Basic Usage

**Increment a ViewCounter in a Controller (show action)

$object->view();

**Get count of Views

$object->views_count();

**Did the user viewed the object?

$object->isViewed();

**Increment the LikeCounter in a Controller (show action)

$object->like();

**Unlike

$object->unlike();

**Get count of Likes

$object->likes_count();

**Did the user liked the object?

$object->isLiked();