PHPackages                             hamedov/laravel-favorites - 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. hamedov/laravel-favorites

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

hamedov/laravel-favorites
=========================

Manage user favorites in laravel application.

4.0.0(3y ago)06431[1 PRs](https://github.com/hamedov93/laravel-favorites/pulls)MITPHPPHP ^8.0.2

Since Apr 1Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hamedov93/laravel-favorites)[ Packagist](https://packagist.org/packages/hamedov/laravel-favorites)[ RSS](/packages/hamedov-laravel-favorites/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (12)Used By (0)

Laravel favorites
=================

[](#laravel-favorites)

Manage user favorites in laravel application.

Installation
============

[](#installation)

`composer require hamedov/laravel-favorites`

Publish config file
===================

[](#publish-config-file)

`php artisan vendor:publish --provider="Hamedov\Favorites\FavoritesServiceProvider" --tag="config"`

Set user model in config file
=============================

[](#set-user-model-in-config-file)

- Make sure you do this before migrations ```
    return [
        'user_model' => \App\User::class,
    ];

    ```

Execute migrations
==================

[](#execute-migrations)

`php artisan migrate`

Setup user model
================

[](#setup-user-model)

- Add `Hamedov\Favorites\HasFavorites` trait to your user model ```
    class User extends Model {
      use HasFavorites;
    }

    ```

Usage
=====

[](#usage)

- Add item to user favorites

    ```
    $book = Book::find(1);
    $user->addFavorite($book);

    $ad = Ad::find(1);
    $user->addFavorite($ad);

    ```
- Remove item from user favorites

    ```
    $book = Book::find(1);
    $user->removeFavorite($book);

    ```
- Get user favorites of specific type

    ```
    $favorites = $user->favorites('App\Book')->get();
    // Or
    $favorites = $user->favorites('App\Book')->paginate(10);

    ```
- Get user favorite ids of specific type

    ```
    // This will return a collection of book ids
    // Passing null as a parameter will return all ids
    $favorites = $user->favoriteIds('App\Book');

    ```
- Get use favorite ids with corresponding types, i.e, pivot table entries

    ```
    $favorables = $user->favorables()->get();
    // Or pass type as parameter to get only specific type
    $favorables = $user->favorables('App\Ad')->get();

    ```
- Remove all user favorites

    ```
    $user->flushFavorites();
    // Or
    $user->flushFavorites('App\Book');

    ```

Available scopes
================

[](#available-scopes)

- `hasFavorite` Scope users who added specific model to favorites

    ```
    $book = Book::find(1);
    $users = App\User::hasFavorite($book)->get();

    ```
- `hasFavoriteOfType` Scope users who add any model of specific type to favorites

    ```
    $users = App\User::hasFavoriteOfType('App\Book')->get();

    ```

License
=======

[](#license)

Released under the Mit license, see [LICENSE](https://github.com/hamedov93/laravel-favorites/blob/master/LICENSE)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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 ~93 days

Recently: every ~174 days

Total

11

Last Release

1298d ago

Major Versions

0.0.5 → 1.0.02020-04-20

1.0.0 → 2.0.02020-11-24

2.0.2 → v3.02021-06-25

v3.0.x-dev → 4.0.02022-10-22

PHP version history (4 changes)0.0.1PHP ^7.2

2.0.0PHP ^7.3

v3.0PHP ^7.3|^8.0

4.0.0PHP ^8.0.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/82c37e59c90c4c4b24cdb4e1dc98084ea2acd19e8cc1e8f7e928af64d39c05f2?d=identicon)[hamedov](/maintainers/hamedov)

---

Top Contributors

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

---

Tags

laravellikesFavorites

### Embed Badge

![Health badge](/badges/hamedov-laravel-favorites/health.svg)

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

###  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)[maize-tech/laravel-markable

Laravel Markable

755229.4k](/packages/maize-tech-laravel-markable)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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