Laravel Likeable
Via Composer
$ composer require draperstudio/laravel-likeable
And then include the service provider within app/config/app.php.
'providers' => [
DraperStudio\Likeable\ServiceProvider::class
];
At last you need to publish and run the migration.
php artisan vendor:publish --provider="DraperStudio\Likeable\ServiceProvider" && php artisan migrate
Usage
Setup a Model
<?php
/*
* This file is part of Laravel Likeable.
*
* (c) DraperStudio <hello@draperstudio.tech>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App;
use DraperStudio\Likeable\Contracts\Likeable;
use DraperStudio\Likeable\Traits\Likeable as LikeableTrait;
use Illuminate\Database\Eloquent\Model;
class Post extends Model implements Likeable
{
use LikeableTrait;
}
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');
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Download