Package Data | |
---|---|
Maintainer Username: | fraank |
Maintainer Contact: | frank.cieslik@gmail.com (Frank Cieslik) |
Package Create Date: | 2015-02-17 |
Package Last Update: | 2015-11-11 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:15:58 |
Package Statistics | |
---|---|
Total Downloads: | 526 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 16 |
Total Watchers: | 2 |
Total Forks: | 7 |
Total Open Issues: | 4 |
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.
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)) }}
**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();