承接 balajidharma/laravel-reaction 相关项目开发

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

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

balajidharma/laravel-reaction

最新稳定版本:v1.0.5

Composer 安装命令:

composer require balajidharma/laravel-reaction

包简介

Reaction management system for Laravel models

README 文档

README

Reaction management system for Laravel models.

Total Downloads Latest Stable Version License

Overview

Laravel Reaction allows you to add reaction to your Laravel models with support for different reaction types.

image

Table of Contents

Installation

  • Install the package via composer
composer require balajidharma/laravel-reaction
  • Publish the migration with
php artisan vendor:publish --provider="BalajiDharma\LaravelReaction\ReactionServiceProvider" --tag="migrations"
  • Run the migration
php artisan migrate
  • To Publish the config/reaction.php config file with
php artisan vendor:publish --provider="BalajiDharma\LaravelReaction\ReactionServiceProvider" --tag="config"
  • Preparing your model

To associate reactor with a model, the model must implement the HasReactor trait:

<?php
namespace App\Models;

use BalajiDharma\LaravelReaction\Traits\HasReactor;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends extends Authenticatable
{
    use HasReactor;
	

To associate reaction with a model, the model must implement the HasReaction trait:

<?php
namespace BalajiDharma\LaravelForum\Models;

use BalajiDharma\LaravelReaction\Traits\HasReaction;
use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    use HasReaction;
	

Add Reaction

use the react method to save the reaction

<?php

$thread->react($type, $name, $user = null, $value = null);

// React with current user
$thread->react('likes', 'like');

$thread->react('likes', 'unlike');

$thread->react('stars', 'star', null, 5);

// React by another user
$user = User::find(1);
$thread->react('likes', 'like', $user);
	

Remove Reactions

<?php

$thread->removeReaction($type, $name = null, $user = null);

// Remove reactions by type
$thread->removeReaction('likes');

// Remove reactions by type and name
$thread->removeReaction('likes', 'like');

$thread->removeReaction('likes', 'unlike');

// Remove reactions by user
$user = User::find(1);
$thread->react('likes', 'like', $user);
	

Get Reactions

<?php

$thread->getReactions($type, $name = null, $user = null);

// Get reactions by type
$thread->getReactions('likes');

// Get reactions by type and name
$thread->getReactions('likes', 'like');

$thread->getReactions('likes', 'unlike');

// Get reactions by user
$user = User::find(1);
$thread->getReactions('likes', null, $user);
$thread->getReactions('likes', 'like', $user);
	

Reaction summary

<?php

$thread->reactionSummary($type);

// example
$article->reactionSummary('likes')->toArray();
// output
/*
[
    "like" => 8,
    "unlike" => -2,
]
*/
	

Check if user reacted

<?php
// check for current user
$thread->isReactBy('likes');

// check for other user
$user = User::find(1);
$thread->isReactBy('likes', $user);
	

Demo

The "Basic Laravel Admin Penel" starter kit come with Laravel Reaction

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-22