PHP code example of jobmetric / laravel-like

1. Go to this page and download the library: Download jobmetric/laravel-like 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/ */

    

jobmetric / laravel-like example snippets


use JobMetric\Reaction\HasReaction;

class Article extends Model
{
    use HasReaction;
}

use JobMetric\Reaction\CanReact;

class User extends Model
{
    use CanReact;
}

$article->addReaction('like', $user); // with user
$article->addReaction('like', null, ['device_id' => 'abc123']); // anonymous

$article->toggleReaction('like', $user); // Adds if not exists, removes if exists

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

$article->removeAllReactions($user); // or pass device_id

$article->updateReaction('like', 'dislike', $user);

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

$article->totalReactions();

$article->countReactions('like');

$article->reactionSummary();
// returns: ['like' => 3, 'dislike' => 1]

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

$article->latestReactions(5);

$article->reactionTo($user);

$user->hasReactedTo($article);

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

$user->reactionSummary(); // ['like' => 3, 'dislike' => 2]

$user->reactedItems(); // Returns models
$user->reactedItems('like', Article::class);

$user->latestReactionsGiven(10);

'reaction' => [
    'prune_days' => 30,
],
bash
php artisan migrate
bash
php artisan model:prune