Skip to content
No description or website provided.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
database/migrations
src
tests
.editorconfig
.gitattributes
.gitignore
.travis.yml
LICENSE MPL 2.0 Jun 9, 2019
README.md
composer.json
phpunit.xml.dist
renovate.json

README.md

Laravel Likeable

Build Status PHP from Packagist Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/likeable

To get started, you'll need to publish the vendor assets and migrate:

php artisan vendor:publish --provider="Artisanry\Likeable\LikeableServiceProvider" && php artisan migrate

Usage

Setup a Model

<?php

namespace App;

use Artisanry\Likeable\HasLikesTrait;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasLikesTrait;
}

Post Model gets liked by User Model

$post->like($user);

Post Model gets disliked by User Model

$post->dislike($user);

Count all likes

$post->likeCount;

Collection of all likes

$post->likes;

Check if the Post Model is currently liked by the User Model

$post->liked($user);

Load posts that are currently liked by the User Model

Post::whereLiked($user)->get();

Count likes the Post Model has

$post->getLikeCount();

Count likes the Post Model has for a specific date

$post->getLikeCountByDate('2015-06-30');

Count likes the Post Model has between two dates

$post->getLikeCountByDate('2015-06-30', '2015-06-31');

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to hello@basecode.sh. All security vulnerabilities will be promptly addressed.

Credits

This project exists thanks to all the people who contribute.

License

Mozilla Public License Version 2.0 (MPL-2.0).

You can’t perform that action at this time.