https://github.com/inpin/lara-like
Trait for Laravel Eloquent models to allow easy implementation of a "like" or "favorite" or "remember" or what ever you want features.
https://github.com/inpin/lara-like
bookmark composer eloquent favorite laralike laravel like likeable model package seen trait
Last synced: 3 months ago
JSON representation
Trait for Laravel Eloquent models to allow easy implementation of a "like" or "favorite" or "remember" or what ever you want features.
- Host: GitHub
- URL: https://github.com/inpin/lara-like
- Owner: inpin
- Created: 2017-10-18T10:50:40.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-05T11:24:06.000Z (over 7 years ago)
- Last Synced: 2025-06-01T13:54:16.495Z (4 months ago)
- Topics: bookmark, composer, eloquent, favorite, laralike, laravel, like, likeable, model, package, seen, trait
- Language: PHP
- Homepage: http://inpinapp.com
- Size: 17.6 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
LaraLike
============
Important note: this product is forked and edited from base [laravel-likeable](https://github.com/rtconner/laravel-likeable) package.[](https://travis-ci.org/inpin/lara-like)
[](https://styleci.io/repos/107395044)
[](https://codeclimate.com/github/inpin/lara-like/maintainability)
[](https://packagist.org/packages/inpin/lara-like)
[](https://packagist.org/packages/inpin/lara-like)
[](https://packagist.org/packages/inpin/lara-like)
[](https://packagist.org/packages/inpin/lara-like)Trait for Laravel Eloquent models to allow easy implementation of a "like" or "favorite" or "remember" or what ever you want features.
#### Composer Install (for Laravel 5.5 and above)
composer require inpin/lara-like
#### Install and then run the migrations
```php
'providers' => [
\Inpin\LaraLike\LaraLikeServiceProvider::class,
],
``````bash
php artisan vendor:publish --provider="Inpin\LaraLike\LaraLikeServiceProvider" --tag=migrations
php artisan migrate
```#### Setup your models
```php
class Book extends \Illuminate\Database\Eloquent\Model {
use Inpin\LaraLike\Likeable;
}
```#### Sample Usage
```php
$book->like(); // like the book for current user
$book->like($user); // pass in your own user
$book->like(0); // just add likes to the count, and don't track by user
$book->like('api'); // like the book for current user with guard 'api'
$book->like(null, 'bookmark') // add book for current user to bookmarks
$book->like($user, 'bookmark') // pass user and type$book->unlike(); // remove like from the book
$book->unlike($user); // pass in your own user id
$book->unlike(0); // remove likes from the count -- does not check for user
$book->unlike('api'); // remove like from book for current user with guard 'api'
$book->unlike(null, 'bookmark') // remove current book from current user bookmarks
$book->unlike($user, 'bookmark') // pass user and type$book->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes
$book->likes()->where('type', 'bookmark')$book->liked(); // check if currently logged in user liked the book
$book->liked($myUserId);$book->likeCount($type); // determine number of likes for given $type (default type is 'like')
Article::whereLikedBy($myUserId) // find only books where user liked them
->with('likeCounter') // highly suggested to allow eager load
->get();
```
note: default type is 'like'.#### Credits
- Mohammad Nourinik - http://inpinapp.com