flarone/laravel-favorable
Composer 安装命令:
composer require flarone/laravel-favorable
包简介
Laravel favorable package to like, dislike and favorite your models
关键字:
README 文档
README
Laravel favorable package to like, dislike and favorite your models.
Composer Install
composer require flarone/laravel-favorable
Then run the migrations
php artisan migrate
Setup your models
class Article extends \Illuminate\Database\Eloquent\Model { use \Flarone\Favoriteable\Favoriteable; }
Sample Usage
$model->favorite(); // favorite the model for current user $model->favorite($myUserId); // pass in your own user id $model->favorite(0); // just add favorites to the count, and don't track by user $model->defavorite(); // remove favorite from the model $model->defavorite($myUserId); // pass in your own user id $model->defavorite(0); // remove favorites from the count -- does not check for user $model->favoriteCount; // get count of favorites $model->favorites; // Iterable Illuminate\Database\Eloquent\Collection of existing favorites $model->favorited(); // check if currently logged in user favorited the model $model->favorited($myUserId); Model::whereFavoritedBy($myUserId) // find only models where user favorited them ->with('favoriteCounter') // highly suggested to allow eager load ->get();
Extending the favorite model
You can extend the favorite model if needed. To do this create your own Favorite model and let it extend the following favorite base model:
\Flarone\Favoriteable\Models\Favorite::class
Next, publish the configuration file with the following command:
php artisan vendor:publish --provider="Flarone\Favoriteable\FavoriteableServiceProvider" --tag="config"
The favorable config file will be copied into your config directory. In this file adjust the favorite_model to your own created model.
Credits
- Flarone - https://flarone.com
统计信息
- 总下载量: 417
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-03