1. Go to this page and download the library: Download qirolab/laravel-reactions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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;
}
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;
}
$user->reactTo($article, 'like');
$article->react('like'); // current login user
$article->react('like', $user);
$user->removeReactionFrom($article);
$article->removeReaction(); // current login user
$article->removeReaction($user);
$user->toggleReactionOn($article, 'like');
$article->toggleReaction('like'); // current login user
$article->toggleReaction('like', $user);
$user->isReactedOn($article));
$article->is_reacted; // current login user
$article->isReactBy(); // current login user
$article->isReactBy($user);
Article::whereReactedBy()->get(); // current login user
Article::whereReactedBy($user)->get();
Article::whereReactedBy($user->id)->get();
// 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);