Download the PHP package servnx/getcandy-favorites without Composer
On this page you can find all versions of the php package servnx/getcandy-favorites. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download servnx/getcandy-favorites
More information about servnx/getcandy-favorites
Files in servnx/getcandy-favorites
Package getcandy-favorites
Short Description Favorites Addon for GetCandy 2
License MIT
Informations about the package getcandy-favorites
GetCandy 2 Favorites Addon
Favorites addon for GetCandy 2 Application.
Installing
Publishing Configurations & Migrations (Optional)
Run Migrations
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).
The Favoriter
The favoriter is the user in which is favoriting objects.
Add the Favoriter Trait to your desired User model.
Usage
Supported GetCandy Favoriteable Models.
Adding favoritebale to your own Models.
API
Get Favoriters example:
Get Favorite Model from User.
This will return a Illuminate\Database\Eloquent\Builder
instance.
Aggregations
List with *_count
attribute:
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 Collection | Paginator | LengthAwarePaginator | array
:
N+1 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:
Events
Event | Description |
---|---|
Servnx\GetCandyFavorite\Events\Favorited |
Triggered when the relationship is created. |
Servnx\GetCandyFavorite\Events\Unfavorited |
Triggered when the relationship is deleted. |
License
MIT
Credits to Overtrue Laravel Favorites.