PHPackages                             christiankuri/laravel-favorite - 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. christiankuri/laravel-favorite

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

christiankuri/laravel-favorite
==============================

Allows Laravel Eloquent models to implement a 'favorite' or 'remember' or 'follow' feature.

v1.4.0(6y ago)226471.2k↑53.3%45[1 issues](https://github.com/ChristianKuri/laravel-favorite/issues)[2 PRs](https://github.com/ChristianKuri/laravel-favorite/pulls)5MITPHPPHP &gt;=5.6.4CI failing

Since Dec 21Pushed 2y ago6 watchersCompare

[ Source](https://github.com/ChristianKuri/laravel-favorite)[ Packagist](https://packagist.org/packages/christiankuri/laravel-favorite)[ Docs](https://github.com/ChristianKuri/laravel-favorite)[ RSS](/packages/christiankuri-laravel-favorite/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (5)

Laravel Favorite (Laravel 5, 6, 7, 8 Package)
=============================================

[](#laravel-favorite-laravel-5-6-7-8-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d50f64ffaaa4fb74a5c88a0304e6add8c8ae86ace47d9d2f5403bccf3b55353e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f43687269737469616e4b7572692f6c61726176656c2d6661766f726974652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ChristianKuri/laravel-favorite)[![Packagist Downloads](https://camo.githubusercontent.com/10c56fea5cefbf8f9ec71fafda662a074beeb2a737723f4f0e82b91db4817649/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f43687269737469616e4b7572692f6c61726176656c2d6661766f726974652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ChristianKuri/laravel-favorite)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/31614a94ae859d9fbed8acbf0ef3146e203df754de65dd69ae9db9ba2056b539/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f43687269737469616e4b7572692f6c61726176656c2d6661766f726974652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ChristianKuri/laravel-favorite)

**Allows Laravel Eloquent models to implement a 'favorite' or 'remember' or 'follow' feature.**

Index
-----

[](#index)

- [Installation](#installation)
- [Models](#models)
- [Usage](#usage)
- [Testing](#testing)
- [Change log](#change-log)
- [Contributions](#contributions)
    - [Pull Requests](#pull-requests)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

1. Install the package via Composer

```
$ composer require christiankuri/laravel-favorite
```

2. 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' => [
    // ...
    ChristianKuri\LaravelFavorite\FavoriteServiceProvider::class,
];
```

3. Publish the database from the command line:

```
php artisan vendor:publish --provider="ChristianKuri\LaravelFavorite\FavoriteServiceProvider"
```

4. Migrate the database from the command line:

```
php artisan migrate
```

Models
------

[](#models)

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

```
use ChristianKuri\LaravelFavorite\Traits\Favoriteability;

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

Your models should import the `Traits/Favoriteable.php` trait and use it, that trait have the methods that you'll use to allow the model be favoriteable. In all the examples I will use the Post model as the model that is 'Favoriteable', thats for example propuses only. (see an example below):

```
use ChristianKuri\LaravelFavorite\Traits\Favoriteable;

class Post extends Model
{
    use Favoriteable;
}
```

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

Usage
-----

[](#usage)

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

### Add to favorites and remove from favorites:

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

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

```
$post = Post::find(1);
$post->addFavorite(); // auth user added to favorites this post
$post->removeFavorite(); // auth user removed from favorites this post
$post->toggleFavorite(); // auth user toggles the favorite status from this post
```

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

```
$post = Post::find(1);
$post->addFavorite(5); // user with that id added to favorites this post
$post->removeFavorite(5); // user with that id removed from favorites this post
$post->toggleFavorite(5); // user with that id toggles the favorite status from this post
```

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

```
$user = User::first();
$post = Post::first();
$user->addFavorite($post); // The user added to favorites this post
$user->removeFavorite($post); // The user removed from favorites this post
$user->toggleFavorite($post); // The user toggles the favorite status from this post
```

### Return the favorite objects for the user:

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

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

```
$user = Auth::user();
$user->favorite(Post::class); // returns a collection with the Posts the User marked as favorite
```

### Return the favorites count from an object:

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

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

```
$post = Post::find(1);
$post->favoritesCount; // returns the number of users that have marked as favorite this object.
```

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

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

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

```
$post = Post::find(1);
$post->favoritedBy(); // returns a collection with the Users that marked the post as favorite.
```

### Check if the user already favorited an object

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

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

```
$post = Post::find(1);
$post->isFavorited(); // returns a boolean with true or false.
```

Testing
-------

[](#testing)

The package have integrated testing, so everytime 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.

Contributions
-------------

[](#contributions)

Contributions are **welcome** and will be fully **credited**. We accept contributions via Pull Requests on [Github](https://github.com/ChristianKuri/laravel-favorite).

### Pull Requests

[](#pull-requests)

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with `$ composer check-style` and fix it with `$ composer fix-style`.
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
- **Create feature branches** - Don't ask us to pull from your master branch.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

Security
--------

[](#security)

Please report any issue you find in the issues page. Pull requests are welcome.

Credits
-------

[](#credits)

- [Christian Kuri](https://github.com/ChristianKuri)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% 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

Every ~260 days

Total

5

Last Release

2394d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/40c2b10d96c11206ccaf3a29b55c320c85acd66b865ab263a2f490e3b7cb8358?d=identicon)[ChristianKuri](/maintainers/ChristianKuri)

---

Top Contributors

[![ChristianKuri](https://avatars.githubusercontent.com/u/17374907?v=4)](https://github.com/ChristianKuri "ChristianKuri (32 commits)")[![jedsonmelo](https://avatars.githubusercontent.com/u/22404267?v=4)](https://github.com/jedsonmelo "jedsonmelo (2 commits)")[![king724](https://avatars.githubusercontent.com/u/350488?v=4)](https://github.com/king724 "king724 (1 commits)")[![renatofmachado](https://avatars.githubusercontent.com/u/4793869?v=4)](https://github.com/renatofmachado "renatofmachado (1 commits)")

---

Tags

eloquent-modelsfavoritefollowlaravel-5-packageliketraitlaravelpackagerememberFollowfavoritefavouriteChristianKurilaravel-favoritefavoritable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/christiankuri-laravel-favorite/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)

PHPackages © 2026

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