bitfumes/laravel-likker

laravel like,laravel liker, laravel love, like, favorite

v5.0 2023-03-21 05:46 UTC

This package is auto-updated.

Last update: 2024-10-21 09:10:10 UTC


README

Software License Build Status Total Downloads GitHub stars GitHub issues

Introduction

This package helps you to have like system in any model. It has very simple api to like and unlike.

Install

composer require bitfumes/laravel-likker

Usage

Prepare Likable Model

Use Likable contract and canBeLiked trait in your model which can be liked.

use Illuminate\Database\Eloquent\Model;
use Bitfumes\Likker\Contracts\Likeable;
use Bitfumes\Likker\Traits\CanBeLiked;

class Post extends Model implements Likeable
{
    use CanBeLiked;
}

Prepare Liker Model

Use Liker contract and canLike trait in your model which can like.

use Illuminate\Foundation\Auth\User as Authenticatable;
use Bitfumes\Likker\Contracts\Liker;
use Bitfumes\Likker\Traits\CanLike;

class User extends Authenticatable implements Liker
{
    use CanLike;
}

Methods Available

Likes

Like a model

// Like by authenticated user
$post->likeIt();
// Like by any user
$post->likeIt($user);

UnLikes

Unlike already liked model

// Remove Like by authenticated user
$post->unLikeIt();
// Like by any user
$post->unLikeIt($user);

Toggle Like

It can toggle like.

// Toggle like by authenticated user
$post->toggleLike();
// Toggle like by any user
$post->toggleLike($user);

Check if Model is alread liked or not

// Return boolean
$post->isLiked();

Like Counts

// it counts the like for given model
$post->countLikes();

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email sarthak@bitfumes.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.