mamadali / yii2-favorites
user favorites extension for yii2 application
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-11-05 15:22:00 UTC
README
The preferred way to install this extension is through composer.
Either run
composer require --prefer-dist mamadali/yii2-favorites "*"
or add
"mamadali/yii2-favorites": "*"
to the require section of your composer.json
file.
then run migrations
php yii migrate/up --migrationPath=@vendor/mamadali/yii2-favorites/migrations
first add to config.php or if use advanced project add to common/config/main.php
'components' => [ ... 'favorites' => [ 'class' => 'mamadali\favorites\Favorite', ], ... ];
Usage
How to add product to user favorites
Yii::$app->favorites->add(Product::class, $product->id);
Note: this method return true when user not loged in
How to remove product from user favorites
Yii::$app->favorites->remove(Product::class, $product->id);
How to check if product is in user favorites
Yii::$app->favorites->has(Product::class, $product->id);
How to get all user favorites from Product model
Yii::$app->favorites->getAll(Product::class);
How to get count of user favorites from Product model
Yii::$app->favorites->getCount(Product::class);
How to get data provider from favorite Products
Yii::$app->favorites->getDataProvider(Product::class);