https://github.com/bitfumes/laravel-likker
Like and unlike package for laravel project
https://github.com/bitfumes/laravel-likker
Last synced: about 2 months ago
JSON representation
Like and unlike package for laravel project
- Host: GitHub
- URL: https://github.com/bitfumes/laravel-likker
- Owner: bitfumes
- License: mit
- Created: 2018-10-10T17:53:44.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-21T05:46:43.000Z (about 2 years ago)
- Last Synced: 2024-05-06T15:01:58.291Z (about 1 year ago)
- Language: PHP
- Size: 101 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Likker
[](LICENSE.md)
[](https://scrutinizer-ci.com/g/bitfumes/laravel-likker/build-status/master)
[](https://packagist.org/packages/bitfumes/laravel-likker)
[](https://github.com/bitfumes/laravel-likker/stargazers)
[](https://github.com/bitfumes/laravel-likker/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.
```php
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.
```php
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
```php
// Like by authenticated user
$post->likeIt();
// Like by any user
$post->likeIt($user);
```#### UnLikes
Unlike already liked model
```php
// Remove Like by authenticated user
$post->unLikeIt();
// Like by any user
$post->unLikeIt($user);
```#### Toggle Like
It can toggle like.
```php
// Toggle like by authenticated user
$post->toggleLike();
// Toggle like by any user
$post->toggleLike($user);
```#### Check if Model is alread liked or not
```php
// Return boolean
$post->isLiked();
```## Like Counts
```php
// it counts the like for given model
$post->countLikes();
```## Testing
Run the tests with:
```bash
vendor/bin/phpunit
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
## License
The MIT License (MIT). Please see [License File](/LICENSE.md) for more information.