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

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

manzadey/laravel-favorite
=========================

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

v3.1(3y ago)25981MITPHPPHP ^8.0|^8.1

Since Dec 21Pushed 3y agoCompare

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

READMEChangelog (2)DependenciesVersions (10)Used By (0)

Laravel Favorite (Laravel 8 Package)
====================================

[](#laravel-favorite-laravel-8-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ebdb9924676495efa79c736aaf44f0701431a691c6ef44ff88379e38e0ebb9e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4d616e7a616465792f6c61726176656c2d6661766f726974652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Manzadey/laravel-favorite)[![Packagist Downloads](https://camo.githubusercontent.com/80bd07b9428c3c98860d8f2e203d87e50200eec650786d78621ac63b600a40e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4d616e7a616465792f6c61726176656c2d6661766f726974652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Manzadey/laravel-favorite)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

**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 manzadey/laravel-favorite
```

2. You need to publish the migration to create the `favorites` table:

```
php artisan vendor:publish --provider="Manzadey\LaravelFavorite\FavoriteServiceProvider" --tag="migrations"
```

3. After that, you need to run migrations:

```
php artisan migrate
```

Publishing the config file
--------------------------

[](#publishing-the-config-file)

Publishing the config file is optional:

```
php artisan vendor:publish --provider="Manzadey\LaravelFavorite\FavoriteServiceProvider" --tag="config"
```

This is the default content of the config file:

```
declare(strict_types=1);

return [

    /*
     * The fully qualified class name of the favorite model.
     */
    'model' => \Manzadey\LaravelFavorite\Models\Favorite::class,

];
```

Models
------

[](#models)

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

```
use Manzadey\LaravelFavorite\Traits\Favoriteability;
use Manzadey\LaravelFavorite\Contracts\FavoriteabilityContract;

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

Your models should import the `Favoriteable` trait, `FavoriteableContract` implements interface and use it, that trait has 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', that's for example proposes only. (see an example below):

```
use Manzadey\LaravelFavorite\Traits\Favoriteable;
use Manzadey\LaravelFavorite\Contracts\FavoriteableContract;

class Post extends Model implements FavoriteableContract
{
    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 favorite with and without an authenticated user (see examples below):

### Add to favorites and remove from favorites:

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

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

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

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

```
$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 `getFavorite()` method in the `User` model.

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

### 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 `favoriteBy()` method in the object

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

### Check if the user already favorite an object

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

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

```
$post = Post::find(1);
$post->isFavorite(); // 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/Manzadey/laravel-favorite).

### Pull Requests

[](#pull-requests)

- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-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)
- [Manzadey Andrey](https://github.com/Manzadey)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~282 days

Recently: every ~314 days

Total

8

Last Release

1450d ago

Major Versions

v1.4.0 → v2.0.02022-03-31

v2.0.0 → v3.02022-04-16

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

v2.0.0PHP ^8.0

v3.0PHP ^8.0|^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34869211?v=4)[Andrey Manzadey](/maintainers/Manzadey)[@Manzadey](https://github.com/Manzadey)

---

Top Contributors

[![ChristianKuri](https://avatars.githubusercontent.com/u/17374907?v=4)](https://github.com/ChristianKuri "ChristianKuri (32 commits)")[![Manzadey](https://avatars.githubusercontent.com/u/34869211?v=4)](https://github.com/Manzadey "Manzadey (12 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

laravelpackagerememberFollowfavoritefavouriteChristianKurilaravel-favoritefavoritableManzadey

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/manzadey-laravel-favorite/health.svg)](https://phpackages.com/packages/manzadey-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)[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)[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

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