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\Like\HasLike;

class Post extends Model
{
    use HasLike;
}

$post = Post::create([
    'status' => 'published',
]);

$user_id = 1;

$post->likeIt($user_id, $type = true);

$post->likeIt($user_id, $type = true);

$post->loadLikeDislikeCount();

$type = $post->isLikedDislikedBy($user_id);

if(\JobMetric\Like\Enums\LikeTypeEnum::LIKE == $type) {
    // liked
} else if(\JobMetric\Like\Enums\LikeTypeEnum::DISLIKE == $type) {
    // disliked
} else {
    // not liked or disliked
}

$post->forgetLike($user_id);

$post->forgetLikes();
bash
php artisan migrate