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

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

ufutx/laravel-favorite
======================

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

v1.3.3(8y ago)61671[1 PRs](https://github.com/glore/laravel-favorite/pulls)MITPHPPHP &gt;=5.5.9

Since Dec 21Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (8)Used By (0)

Laravel Favorite (Laravel 5 Package, forked from Ufutx/laravel-favorite)
========================================================================

[](#laravel-favorite-laravel-5-package-forked-from-ufutxlaravel-favorite)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8a807eaa2baaa442fa4345eb46e010a1333cc02e566da3071641d8b00e51e5e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f55667574782f6c61726176656c2d6661766f726974652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Ufutx/laravel-favorite)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/5752b94ab57d4603342c2ea66640a52436cac4254efd1ac99b480bd90d3b5c3a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f55667574782f6c61726176656c2d6661766f726974652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Ufutx/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 ufutx/laravel-favorite
```

2. Update `config/app.php` by adding an entry for the service provider.

```
'providers' => [
    // ...
    Ufutx\LaravelFavorite\FavoriteServiceProvider::class,
];
```

3. 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 Ufutx\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 Ufutx\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.
```

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/Ufutx/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/Ufutx)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 63.3% 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 ~56 days

Recently: every ~70 days

Total

7

Last Release

3090d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6.4

v1.3.1PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/52f791025e535f8973e619977e99c52043d1db3b4b14109bb348c48ccb352a47?d=identicon)[glore](/maintainers/glore)

---

Top Contributors

[![ChristianKuri](https://avatars.githubusercontent.com/u/17374907?v=4)](https://github.com/ChristianKuri "ChristianKuri (19 commits)")[![glore](https://avatars.githubusercontent.com/u/2793574?v=4)](https://github.com/glore "glore (11 commits)")

---

Tags

laravelpackagerememberFollowfavoritefavouritelaravel-favoritefavoritableUfutxglore

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[christiankuri/laravel-favorite

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

226471.2k5](/packages/christiankuri-laravel-favorite)[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)
