承接 flarone/laravel-favorable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

统计信息

  • 总下载量: 417
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固