PHPackages                             servnx/getcandy-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. servnx/getcandy-favorites

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

servnx/getcandy-favorites
=========================

Favorites Addon for GetCandy 2

v1.0-beta.4(4y ago)51MITPHP

Since Apr 11Pushed 4y ago2 watchersCompare

[ Source](https://github.com/ServNX/getcandy-favorites)[ Packagist](https://packagist.org/packages/servnx/getcandy-favorites)[ RSS](/packages/servnx-getcandy-favorites/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (4)Dependencies (5)Versions (8)Used By (0)

GetCandy 2 Favorites Addon
--------------------------

[](#getcandy-2-favorites-addon)

Favorites addon for GetCandy 2 Application.

Installing
----------

[](#installing)

```
composer require servnx/getcandy-favorites

```

### Publishing Configurations &amp; Migrations (Optional)

[](#publishing-configurations--migrations-optional)

```
php artisan vendor:publish --tag="getcandy-favorites"
```

### Run Migrations

[](#run-migrations)

```
php artisan migrate
```

### Adding screens to GetCandy Admin Hub (Optional)

[](#adding-screens-to-getcandy-admin-hub-optional)

If you have the admin hub installed, you can enable the screens by publishing the configs demonstrated above and setting the `hub` value to `true` (false by default).

```
/*
* If you have GetCandy Admin Hub installed set this to true (default is false).
*/
'hub' => true,
```

### The Favoriter

[](#the-favoriter)

The **favoriter** is the **user** in which is favoriting objects.

Add the **Favoriter Trait** to your desired User model.

```
use Servnx\GetCandyFavorite\Traits\Favoriter;

class User extends Authenticatable
{
    use HasFactory,
        GetCandyUser,
        Favoriter,
        Billable,
        Notifiable;

    ...
}
```

Usage
-----

[](#usage)

### Supported GetCandy Favoriteable Models.

[](#supported-getcandy-favoriteable-models)

```
GetCandy\Models\Product::class
... more to come ...
```

### Adding favoritebale to your own Models.

[](#adding-favoritebale-to-your-own-models)

```
use Illuminate\Database\Eloquent\Model;
use Servnx\GetCandyFavorite\Traits\Favoriteable;

class Post extends Model
{
    use Favoriteable;

    ...
}
```

### API

[](#api)

```
$user = User::find(1);
$product = Product::find(2);

$user->favorite($product);
$user->unfavorite($product);
$user->toggleFavorite($product);
$user->getFavoriteItems(Product::class)

$user->hasFavorited($product);
$product->hasBeenFavoritedBy($user);
```

#### Get Favoriters example:

[](#get-favoriters-example)

```
foreach($product->favoriters as $user) {
    ...
}
```

#### Get Favorite Model from User.

[](#get-favorite-model-from-user)

This will return a `Illuminate\Database\Eloquent\Builder` instance.

```
$favoriteItems = $user->getFavoriteItems(Product::class);

// more examples
$favoriteItems->get();
$favoriteItems->paginate();
$favoriteItems->find(1)->get();
```

### Aggregations

[](#aggregations)

```
// all favorites by this user
$user->favorites->count();

// how many Products has this user favorited ?
$user->favorites()->withType(Product::class)->count();

// how many users favorited this product ?
$product->favoriters->count();
```

List with `*_count` attribute:

```
$users = User::withCount('favorites')->get();

foreach($users as $user) {
    echo $user->favorites_count;
}

// for Favoriteable models:
$products = Product::withCount('favoriters')->get();

foreach($products as $product) {
    echo $product->favoriters_count;
}
```

### Attach user favorite status to favoriteable collection

[](#attach-user-favorite-status-to-favoriteable-collection)

You can use `Favoriter::attachFavoriteStatus($favoriteables)` to attach the user favorite status, it will set `has_favorited` attribute to each model of `$favoriteables`:

#### For `Models`

[](#for-models)

```
$product = Product::find(1);

$product = $user->attachFavoriteStatus($product);

$product->toArray();

// example result
[
    "id" => 1
    ...
    "has_favorited" => true
],
```

#### For `Collection | Paginator | LengthAwarePaginator | array`:

[](#for-collection--paginator--lengthawarepaginator--array)

```
$products = Product::oldest('id')->get();

$products = $user->attachFavoriteStatus($products);

$products->toArray();

// example result
[
  [
    "id" => 1
    ...
    "has_favorited" => true
  ],
  [
    "id" => 2
    ...
    "has_favorited" => false
  ],
  [
    "id" => 3
    ...
    "has_favorited" => true
  ],
]
```

### N+1 issue

[](#n1-issue)

To avoid the N+1 issue, you can use eager loading to reduce this operation to just 2 queries. When querying, you may specify which relationships should be eager loaded using the `with` method:

```
// Favoriter
$users = User::with('favorites')->get();

// Favoriteable
$products = Product::with('favorites')->get();
$products = Product::with('favoriters')->get();
```

### Events

[](#events)

**Event****Description**`Servnx\GetCandyFavorite\Events\Favorited`Triggered when the relationship is created.`Servnx\GetCandyFavorite\Events\Unfavorited`Triggered when the relationship is deleted.License
-------

[](#license)

MIT

Credits to [Overtrue Laravel Favorites](https://github.com/overtrue/laravel-favorite).

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

4

Last Release

1489d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/servnx-getcandy-favorites/health.svg)

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

###  Alternatives

[shjia/taobao_spider

淘宝、天猫商品爬虫

191.2k](/packages/shjia-taobao-spider)[webelightdev/laravel-slider

configer slider from UI

131.0k](/packages/webelightdev-laravel-slider)

PHPackages © 2026

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