2017 © Pedro Peláez
 

library evaluation

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

image

sukohi/evaluation

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  • Tuesday, October 3, 2017
  • by Sukohi
  • Repository
  • 2 Watchers
  • 11 Stars
  • 868 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 18 Versions
  • 30 % Grown

The README.md

Evaluation

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER. (This package is maintained under L5.5.), (*1)

Installation

Execute the following composer command., (*2)

composer require sukohi/evaluation:4.*

Register the service provider in app.php.
If you are in L5.5+ you don't need the above., (*3)

'providers' => [
    //...Others...,  
    Sukohi\Evaluation\EvaluationServiceProvider::class,
]

Preparation

To make a table for this package, execute the following commands., (*4)

php artisan vendor:publish --provider="Sukohi\Evaluation\EvaluationServiceProvider"

and, (*5)

php artisan migrate

Usage

Add EvaluationTrait to your model like so., (*6)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Sukohi\Evaluation\EvaluationTrait;

class Item extends Model
{
    use EvaluationTrait;
}

Now you can use new methods from EvaluationTrait., (*7)

Like

$item = \App\Item::find(1);

/*  Add `like`  */
$item->like($user_id);  // You also can set empty ID.

/*  Remove `like`  */
$item->unlike($user_id);
$item->unlike(['user_id' => $user_id]);
$item->unlike(['ip' => $ip]);
$item->unlike(['user_agent' => $user_agent]);

/*  Remove all `like`s  */
$item->clearLike();

/*  Has  */
$item->hasLike($user_id)    // True or False
$item->hasLike(['user_id' => $user_id]);
$item->hasLike(['ip' => $ip]);
$item->hasLike(['user_agent' => $user_agent]);

/*  Count  */
echo $item->like_count;

Dislike

$item = \App\Item::find(1);

/*  Add `dislike`  */
$item->dislike($user_id);  // You also can set empty ID.

/*  Remove `dislike`  */
$item->undislike($user_id);
$item->undislike(['user_id' => $user_id]);
$item->undislike(['ip' => $ip]);
$item->undislike(['user_agent' => $user_agent]);

/*  Remove all `dislike`s  */
$item->clearDislike();

/*  Has  */
$item->hasDislike($user_id)    // True or False
$item->hasDislike(['user_id' => $user_id]);
$item->hasDislike(['ip' => $ip]);
$item->hasDislike(['user_agent' => $user_agent]);

/*  Count  */
echo $item->dislike_count;

Favorite

$item = \App\Item::find(1);

/*  Add `favorite`  */
$item->favorite($user_id);  // You need to set user ID.

/*  Remove `favorite`  */
$item->unfavorite($user_id);
$item->unfavorite(['user_id' => $user_id]);
$item->unfavorite(['ip' => $ip]);
$item->unfavorite(['user_agent' => $user_agent]);

/*  Remove all `favorite`s  */
$item->clearFavorite();

/*  Has  */
$item->hasFavorite($user_id)    // True or False
$item->hasFavorite(['user_id' => $user_id]);
$item->hasFavorite(['ip' => $ip]);
$item->hasFavorite(['user_agent' => $user_agent]);

/*  Count  */
echo $item->favorite_count;

Remember

$item = \App\Item::find(1);

/*  Add `remember`  */
$item->remember($user_id);  // You need to set user ID.

/*  Remove `remember`  */
$item->unremember($user_id);
$item->unremember(['user_id' => $user_id]);
$item->unremember(['ip' => $ip]);
$item->unremember(['user_agent' => $user_agent]);

/*  Remove all `remember`s  */
$item->clearRemember();

/*  Has  */
$item->hasRemember($user_id)    // True or False
$item->hasRemember(['user_id' => $user_id]);
$item->hasRemember(['ip' => $ip]);
$item->hasRemember(['user_agent' => $user_agent]);

/*  Count  */
echo $item->remember_count;

Where Clause

$user_id = 1;
$ip = request()->ip();
$user_agent = request()->userAgent();

// Like
$items = \App\Item::whereHasLike()->get();
$items = \App\Item::whereHasLike($user_id)->get();
$items = \App\Item::whereHasLike(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasLike(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasLike(['ip' => $ip])->get();
$items = \App\Item::where('id', 1)->orWhereHasLike(['user_agent' => $user_agent])->get();

// Dislike
$items = \App\Item::whereHasDislike()->get();
$items = \App\Item::whereHasDislike($user_id)->get();
$items = \App\Item::whereHasDislike(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasDislike(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasDislike(['ip' => $ip])->get();
$items = \App\Item::where('id', 1)->orWhereHasDislike(['user_agent' => $user_agent])->get();

// Favorite
$items = \App\Item::whereHasFavorite()->get();
$items = \App\Item::whereHasFavorite($user_id)->get();
$items = \App\Item::whereHasFavorite(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasFavorite(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasFavorite(['ip' => $ip])->get();
$items = \App\Item::where('id', 1)->orWhereHasFavorite(['user_agent' => $user_agent])->get();

// Remember
$items = \App\Item::whereHasRemember()->get();
$items = \App\Item::whereHasRemember($user_id)->get();
$items = \App\Item::whereHasRemember(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasRemember(['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasRemember(['ip' => $ip])->get();
$items = \App\Item::where('id', 1)->orWhereHasRemember(['user_agent' => $user_agent])->get();

Or, (*8)

$type = 'like'; // like, dislike, favorite or remember

// And
$items = \App\Item::whereHasEvaluations($type)->get();
$items = \App\Item::\App\Music::whereHasEvaluations($type, ['user_id' => $user_id])->get();
$items = \App\Item::\App\Music::whereHasEvaluations($type, ['ip' => $ip])->get();
$items = \App\Item::\App\Music::whereHasEvaluations($type, ['user_agent' => $user_agent])->get();

// Or
$items = \App\Item::where('id', 1)->orWhereHasEvaluations($type)->get();
$items = \App\Item::where('id', 1)->orWhereHasEvaluations($type, ['user_id' => $user_id])->get();
$items = \App\Item::where('id', 1)->orWhereHasEvaluations($type, ['ip' => $ip])->get();
$items = \App\Item::where('id', 1)->orWhereHasEvaluations($type, ['user_agent' => $user_agent])->get();
  • This feature is from hikernl. Thank you!

Order By Clause

$direction = 'asc'; // or desc
\App\Item::orderByLike($direction)->get();
\App\Item::orderByDislike($direction)->get();
\App\Item::orderByFavorite($direction)->get();
\App\Item::orderByRemember($direction)->get();

// or

\App\Item::orderByEvaluation('like', $direction)->get();
\App\Item::orderByEvaluation('dislike', $direction)->get();
\App\Item::orderByEvaluation('favorite', $direction)->get();
\App\Item::orderByEvaluation('remember', $direction)->get();

Duplication

If you want to allow users to add duplicate evaluation point(s), please use the following methods., (*9)

$music->allowEvaluationDuplications([
    'user_id' => false,
    'ip' => false,
    'user_agent' => true,
]);

// or

$item->allowEvaluationDuplicationByUserId($boolean);      // Default: false

$item->allowEvaluationDuplicationByIpAddress($boolean);   // Default: false

$item->allowEvaluationDuplicationByUserAgent($boolean);   // Default: true

Note: favorite and remember can NOT duplicate user ID per item because they should solely have the point., (*10)

License

This package is licensed under the MIT License., (*11)

Copyright 2017 Sukohi Kuhoh, (*12)

The Versions

03/10 2017

dev-master

9999999-dev

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/10 2017

4.0.x-dev

4.0.9999999.9999999-dev

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/10 2017

4.0.5

4.0.5.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/10 2017

4.0.4

4.0.4.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/10 2017

4.0.3

4.0.3.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/10 2017

4.0.2

4.0.2.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/10 2017

4.0.1

4.0.1.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/10 2017

4.0.0

4.0.0.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

21/05 2017

3.0.x-dev

3.0.9999999.9999999-dev

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

31/01 2017

3.0.0

3.0.0.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

13/09 2016

2.0.x-dev

2.0.9999999.9999999-dev

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

13/09 2016

2.0.6

2.0.6.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

22/08 2016

2.0.5

2.0.5.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/08 2016

2.0.4

2.0.4.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/08 2016

2.0.3

2.0.3.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/08 2016

2.0.2

2.0.2.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/08 2016

2.0.1

2.0.1.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

03/08 2016

2.0.0

2.0.0.0

A Laravel package to manage evaluation data like LIKE, DISLIKE, FAVORITE and REMEMBER.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi