PHPackages                             hayrullah/laravel-likes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hayrullah/laravel-likes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hayrullah/laravel-likes
=======================

This Library improved to record request likes and make statistics for all links which liked.

v1.0(5y ago)17MITPHPPHP &gt;=7.1.0CI failing

Since May 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/zaherkhirullah/laravel-likes)[ Packagist](https://packagist.org/packages/hayrullah/laravel-likes)[ RSS](/packages/hayrullah-laravel-likes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Laravel Likes Management System
===============================

[](#laravel-likes-management-system)

[![Latest Version on Packagist](https://camo.githubusercontent.com/832a7fd1b2bb39d929effb15035e637ab79988bfe87a7e610baa3a49071877a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68617972756c6c61682f6c61726176656c2d6c696b65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hayrullah/laravel-likes)[](https://github.com/hayrullah/laravel-likes/workflows/Run%20Tests/badge.svg?branch=master)[![Total Downloads](https://camo.githubusercontent.com/c429493656bfb4a2cb01700eb3024167e64a17f3e451cb56eef2fba7a60e8f0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68617972756c6c61682f6c61726176656c2d6c696b65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hayrullah/laravel-likes)[![PHP Composer](https://github.com/zaherkhirullah/laravel-likes/workflows/PHP%20Composer/badge.svg?branch=master)](https://github.com/zaherkhirullah/laravel-likes/workflows/PHP%20Composer/badge.svg?branch=master)[![GitHub license](https://camo.githubusercontent.com/b4178437d21b4c93f5255f07f8fb3a13f20a10aaddc633022f6e5aec6155f3c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7a616865726b686972756c6c61682f6c61726176656c2d6c696b6573)](https://github.com/zaherkhirullah/laravel-likes)[![Quality Score](https://camo.githubusercontent.com/61334f0ef9297f6c234a536559df72f14a8520b8faa75914b16ae637164aa039/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a616865726b686972756c6c61682f6c61726176656c2d6c696b65732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/zaherkhirullah/laravel-likes)[![`StyleCI](https://camo.githubusercontent.com/d6f9dfe042318dd7b58dee71c765cde77b6347d9741686ba520e743e1bd66fd3/68747470733a2f2f7374796c6563692e696f2f7265706f732f3236353132363734302f736869656c64)](https://styleci.io/repos/265126740)

Documentation, Installation, and Usage Instructions
---------------------------------------------------

[](#documentation-installation-and-usage-instructions)

See the [DOCUMENTATION](https://packagist.org/packages/hayrullah/laravel-likes) for detailed installation and usage instructions.

### INSTALLATION

[](#installation)

```
$ composer require hayrullah/laravel-likes
```

- In Laravel &gt;=5.5 this package will automatically get registered. For older versions, update your `config/app.php` by adding an entry for the service provider.

```
'providers' => [
    // ...
    Hayrullah\Likes\LikeServiceProvider::class,
];
```

- Publish the database from the command line:

```
php artisan vendor:publish --provider="Hayrullah\Likes\LikeServiceProvider"
```

- Migrate the database from the command line:

```
php artisan migrate
```

Models
------

[](#models)

Your User model should import the `Traits/Likability.php` trait and use it, that trait allows the user to like the models. (see an example below):

```
use Hayrullah\Likes\Traits\Likability;

class User extends Authenticatable
{
    use Likability;
}
```

Your models should import the `Traits/Likable.php` trait and use it, that trait have the methods that you'll use to allow the model be likable. In all the examples I will use the Article model as the model that is 'Likable', thats for example propuses only.

- see an example below:

```
use Hayrullah\Likes\Traits\Likable;

class Article extends Model
{
    use Likable;
}
```

That's it ... your model is now **"likable"**! Now the User can like models that have the likable trait.

Usage
-----

[](#usage)

The models can be liked with and without an authenticated user (see examples below):

### Add to likes and remove from likes:

[](#add-to-likes-and-remove-from-likes)

If no param is passed in the like method, then the model will asume the auth user.

```
$article = Article::first();
$article->addLike();    // auth user added to likes this article
$article->removeLike(); // auth user removed from likes this article
$article->toggleLike(); // auth user toggles the like status from this article
```

If a param is passed in the like method, then the model will asume the user with that id.

```
$article = Article::first();
$article->addLike(5);    // user with that id added to likes this article
$article->removeLike(5); // user with that id removed from likes this article
$article->toggleLike(5); // user with that id toggles the like status from this article
```

The user model can also add to likes and remove from favrites:

```
$user = User::first();
$article = Article::first();
$user->addLike($article);    // The user added to likes this article
$user->removeLike($article); // The user removed from likes this article
$user->toggleLike($article); // The user toggles the like status from this article
```

### Return the like objects for the user:

[](#return-the-like-objects-for-the-user)

A user can return the objects he marked as like. You just need to pass the **class** in the `like()` method in the `User` model.

```
$user = Auth::user();
$user->like(Article::class); // returns a collection with the Articles the User marked as like
```

### Return the likes count from an object:

[](#return-the-likes-count-from-an-object)

You can return the likes count from an object, you just need to return the `likesCount` attribute from the model

```
$article = Article::first();
$article->likesCount; // returns the number of users that have marked as like this object.
```

### Return the users who marked this object as like

[](#return-the-users-who-marked-this-object-as-like)

You can return the users who marked this object, you just need to call the `likedBy()` method in the object

```
$article = Article::first();
$article->likedBy(); // returns a collection with the Users that marked the article as like.
```

### Check if the user already liked an object

[](#check-if-the-user-already-liked-an-object)

You can check if the Auth user have already liked an object, you just need to call the `isLiked()` method in the object

```
$article = Article::first();
$article->isLiked(); // returns a boolean with true or false.
```

Testing
-------

[](#testing)

The package have integrated testing, so every time you make a pull request your code will be tested.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2185d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f43319c6ad05f50917e7ab7c3468b81f50cacd8ba43f09bca7cf575e3fbc393d?d=identicon)[zaherkhirullah](/maintainers/zaherkhirullah)

---

Top Contributors

[![zaherkhirullah](https://avatars.githubusercontent.com/u/22406442?v=4)](https://github.com/zaherkhirullah "zaherkhirullah (5 commits)")

---

Tags

likelikeslaravel likespage likesmodel likeslike countrylike statisticslike recordslike counter

### Embed Badge

![Health badge](/badges/hayrullah-laravel-likes/health.svg)

```
[![Health](https://phpackages.com/badges/hayrullah-laravel-likes/health.svg)](https://phpackages.com/packages/hayrullah-laravel-likes)
```

###  Alternatives

[maize-tech/laravel-markable

Laravel Markable

755229.4k](/packages/maize-tech-laravel-markable)[risul/laravel-like-comment

Ajax based site wide like and comment system for laravel

1116.9k](/packages/risul-laravel-like-comment)[hauntd/yii2-vote

Votes, likes, favorites.

383.1k](/packages/hauntd-yii2-vote)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
