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

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

stepanenko3/laravel-favorite
============================

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

1.0.2(6y ago)520MITPHPPHP &gt;=5.6.4CI failing

Since Mar 26Pushed 6y ago1 watchersCompare

[ Source](https://github.com/stepanenko3/laravel-favorite)[ Packagist](https://packagist.org/packages/stepanenko3/laravel-favorite)[ Docs](https://github.com/Stepanenko3/laravel-favorite)[ RSS](/packages/stepanenko3-laravel-favorite/feed)WikiDiscussions master Synced today

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

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

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/eda58772fc6dc17a4013e15ee87fdc9425809688718ed775f1e34d441e670271/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f53746570616e656e6b6f332f6c61726176656c2d6661766f726974652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Stepanenko3/laravel-favorite)[![Packagist Downloads](https://camo.githubusercontent.com/fefa23696ad7e00dcb0ba723ddfcdb8d0d4955975d1adabeda75547214f2ec9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f53746570616e656e6b6f332f6c61726176656c2d6661766f726974652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Stepanenko3/laravel-favorite)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/0ba6ad24dc3594bef59fe63220c2f9f074b0ea6eb786e3ad3f72d9b57f8e2cdc/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f53746570616e656e6b6f332f6c61726176656c2d6661766f726974652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Stepanenko3/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 Stepanenko3/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' => [
    // ...
    Stepanenko3\LaravelFavorite\FavoriteServiceProvider::class,
];
```

3. Publish the database from the command line:

```
php artisan vendor:publish --provider="Stepanenko3\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 Stepanenko3\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 Stepanenko3\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/Stepanenko3/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)

- [Artem Stepanenko](https://github.com/Stepanenko3)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Every ~0 days

Total

3

Last Release

2237d ago

### Community

Maintainers

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

---

Top Contributors

[![stepanenko3](https://avatars.githubusercontent.com/u/31134245?v=4)](https://github.com/stepanenko3 "stepanenko3 (1 commits)")

---

Tags

laravelpackagerememberFollowfavoritefavouritelaravel-favoritefavoritableStepanenko3

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/stepanenko3-laravel-favorite/health.svg)](https://phpackages.com/packages/stepanenko3-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.0M686](/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)
