fraank/view-counter

A view and like counter extension for your laravel project.
526 16
Install
composer require fraank/view-counter
PHP:>=5.4.0
License:MIT
Last Updated:Nov 11, 2015
Links: GitHub  ·  Packagist
Maintainer: fraank

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 fraank/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:

Fraank\ViewCounter\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 Fraank\ViewCounter\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();

Related Packages

exa2040/laravel-view-counter

A view and like counter extension for your laravel project.

17 0
craneplus/view-counter

A view and like counter extension for your laravel project

11 0
cyrildewit/eloquent-viewable

Laravel package that allows you to associate views with Eloquent models

1,191,682 885
duncan3dc/blade

Use Laravel Blade templates without the full Laravel framework

511,627 148
larablocks/pigeon

A more flexible email message builder for Laravel 5 including chained methods, r...

3,706 14