All Projects → qirolab → Laravel Reactions

qirolab / Laravel Reactions

Licence: mit
Laravel reactions package for implementing reactions (eg: like, dislike, love, emotion, etc) on Eloquent models.

Projects that are alternatives of or similar to Laravel Reactions

Laravel Love
Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?
Stars: ✭ 822 (+1317.24%)
Mutual labels:  eloquent, laravel, star, rating, rate, emotion
Laravel Likeable
Rate Eloquent models with Likes and Dislikes in Laravel. Development moved to Laravel Love package!
Stars: ✭ 95 (+63.79%)
Mutual labels:  eloquent, laravel, rating, rate, emotion
Starrate
swift电商五星评价,星星评分控件,支持自定义数量、拖拽、间隔、设置最小星星数等操作
Stars: ✭ 85 (+46.55%)
Mutual labels:  star, rating, rate
Rating
Laravel Eloquent Rating allows you to assign ratings to any model.
Stars: ✭ 175 (+201.72%)
Mutual labels:  eloquent, laravel, rating
Improved Polymorphic Eloquent Builder
🔨 Improved Polymorphic Eloquent Builder
Stars: ✭ 12 (-79.31%)
Mutual labels:  eloquent, laravel
Lighthouse Utils
An add-on to Lighthouse to auto-generate CRUD actions from types https://github.com/nuwave/lighthouse
Stars: ✭ 26 (-55.17%)
Mutual labels:  eloquent, laravel
Laravel Reviewable
Adds a reviewable feature to your laravel app.
Stars: ✭ 57 (-1.72%)
Mutual labels:  laravel, rating
Rememberable
Query caching for Laravel
Stars: ✭ 960 (+1555.17%)
Mutual labels:  eloquent, laravel
Eloquent Ldap
A Laravel 5.1 package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.
Stars: ✭ 19 (-67.24%)
Mutual labels:  eloquent, laravel
Eloquent Driver
A package that allows you to store Statamic entries in a database.
Stars: ✭ 28 (-51.72%)
Mutual labels:  eloquent, laravel
Time Traveller
Time travel for your Laravel Models.
Stars: ✭ 36 (-37.93%)
Mutual labels:  eloquent, laravel
Eloquent Filter
This simple package helps you filter Eloquent data using query filters.
Stars: ✭ 24 (-58.62%)
Mutual labels:  eloquent, laravel
Eloquent Sortable
Sortable behaviour for Eloquent models
Stars: ✭ 914 (+1475.86%)
Mutual labels:  eloquent, laravel
Awesomstar
Awesome (star)rating system with PHP, MySQL and pure JavaScript.
Stars: ✭ 15 (-74.14%)
Mutual labels:  star, rating
Validating
Automatically validating Eloquent models for Laravel
Stars: ✭ 906 (+1462.07%)
Mutual labels:  eloquent, laravel
Gorose
GoRose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides six major database drivers: mysql,sqlite3,postgres,oracle,mssql, Clickhouse.
Stars: ✭ 947 (+1532.76%)
Mutual labels:  eloquent, laravel
Freelancers Market
Laravel Project to help freelance websites clients and freelancers to find each other.
Stars: ✭ 39 (-32.76%)
Mutual labels:  eloquent, laravel
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-32.76%)
Mutual labels:  eloquent, laravel
Laravel Tags
Add tags and taggable behaviour to your Laravel app
Stars: ✭ 1,026 (+1668.97%)
Mutual labels:  eloquent, laravel
Laravel Graphql
GraphQL implementation with power of Laravel
Stars: ✭ 56 (-3.45%)
Mutual labels:  eloquent, laravel

Add Reactions (like, dislike, etc.) to Eloquent Model

Latest Version on Packagist GitHub Tests Action Status Styling Psalm Total Downloads

Laravel reactions package for implementing reactions (eg: like, dislike, love, emotion etc) on Eloquent models.

Video Tutorial

▶️ Laravel Reactions Tutorial

Installation

Download package into the project using Composer.

$ composer require qirolab/laravel-reactions

Registering package

Laravel 5.5 (or higher) uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

For Laravel 5.4 or earlier releases version include the service provider within app/config/app.php:

'providers' => [
    Qirolab\Laravel\Reactions\ReactionsServiceProvider::class,
],

Database Migration

If you want to make changes in migrations, publish them to your application first.

$ php artisan vendor:publish --provider="Qirolab\Laravel\Reactions\ReactionsServiceProvider" --tag=migrations

Run database migrations.

$ php artisan migrate

Usage

Prepare Reacts (User) Model

Use Qirolab\Laravel\Reactions\Contracts\ReactsInterface contract in model which will perform react behavior on reactable model and implement it and use Qirolab\Laravel\Reactions\Traits\Reacts trait.

use Qirolab\Laravel\Reactions\Traits\Reacts;
use Qirolab\Laravel\Reactions\Contracts\ReactsInterface;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements ReactsInterface
{
    use Reacts;
}

Prepare Reactable Model

Use Qirolab\Laravel\Reactions\Contracts\ReactableInterface contract in model which will get reaction behavior and implement it and use Qirolab\Laravel\Reactions\Traits\Reactable trait.

use Illuminate\Database\Eloquent\Model;
use Qirolab\Laravel\Reactions\Traits\Reactable;
use Qirolab\Laravel\Reactions\Contracts\ReactableInterface;

class Article extends Model implements ReactableInterface
{
    use Reactable;
}

Available Methods

Reaction

$user->reactTo($article, 'like');

$article->react('like'); // current login user
$article->react('like', $user);

Remove Reaction

Removing reaction of user from reactable model.

$user->removeReactionFrom($article);

$article->removeReaction(); // current login user
$article->removeReaction($user);

Toggle Reaction

The toggle reaction method will add a reaction to the model if the user has not reacted. If a user has already reacted, then it will replace the previous reaction with a new reaction. For example, if the user has reacted 'like' on the model. Now on toggles reaction to 'dislike' then it will remove the 'like' and stores the 'dislike' reaction.

If a user has reacted like then on toggle reaction with like. It will remove the reaction.

$user->toggleReactionOn($article, 'like');

$article->toggleReaction('like'); // current login user
$article->toggleReaction('like', $user);

Boolean check if user reacted on model

$user->isReactedOn($article));

$article->is_reacted; // current login user
$article->isReactBy(); // current login user
$article->isReactBy($user);

Reaction summary on model

$article->reactionSummary();
$article->reaction_summary;

// example
$article->reaction_summary->toArray();
// output
/*
[
    "like" => 5,
    "dislike" => 2,
    "clap" => 4,
    "hooray" => 1
]
*/

Get collection of users who reacted on model

$article->reactionsBy();

Scopes

Find all articles reacted by user.

Article::whereReactedBy()->get(); // current login user

Article::whereReactedBy($user)->get();
Article::whereReactedBy($user->id)->get();

Reaction on Model

// It will return the Reaction object that is reacted by given user.
$article->reacted($user);
$article->reacted(); // current login user
$article->reacted; // current login user

$user->reactedOn($article);

Events

On each reaction added \Qirolab\Laravel\Reactions\Events\OnReaction event is fired.

On each reaction removed \Qirolab\Laravel\Reactions\Events\OnDeleteReaction event is fired.

Testing

Run the tests with:

$ vendor/bin/phpunit
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].