PHP code example of balajidharma / laravel-reaction
1. Go to this page and download the library: Download balajidharma/laravel-reaction 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/ */
balajidharma / laravel-reaction example snippets
namespace App\Models;
use BalajiDharma\LaravelReaction\Traits\HasReactor;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends extends Authenticatable
{
use HasReactor;
namespace BalajiDharma\LaravelForum\Models;
use BalajiDharma\LaravelReaction\Traits\HasReaction;
use Illuminate\Database\Eloquent\Model;
class Thread extends Model
{
use HasReaction;
$thread->react($type, $name, $user = null, $value = null);
// React with current user
$thread->react('likes', 'like');
$thread->react('likes', 'unlike');
$thread->react('stars', 'star', null, 5);
// React by another user
$user = User::find(1);
$thread->react('likes', 'like', $user);
$thread->removeReaction($type, $name = null, $user = null);
// Remove reactions by type
$thread->removeReaction('likes');
// Remove reactions by type and name
$thread->removeReaction('likes', 'like');
$thread->removeReaction('likes', 'unlike');
// Remove reactions by user
$user = User::find(1);
$thread->react('likes', 'like', $user);
$thread->getReactions($type, $name = null, $user = null);
// Get reactions by type
$thread->getReactions('likes');
// Get reactions by type and name
$thread->getReactions('likes', 'like');
$thread->getReactions('likes', 'unlike');
// Get reactions by user
$user = User::find(1);
$thread->getReactions('likes', null, $user);
$thread->getReactions('likes', 'like', $user);