manzadey/laravel-like 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

manzadey/laravel-like

Composer 安装命令:

composer require manzadey/laravel-like

包简介

Allows Laravel Eloquent models to implement a 'like'

README 文档

README

Latest Version on Packagist Total Downloads Software License

This package implements the likes/dislikes system in the laravel framework.

Index

Installation

You can install the package via composer:

  1. Install the package via Composer
composer require manzadey/laravel-like
  1. Publish the database from the command line:
php artisan vendor:publish --provider="Manzadey\LaravelLike\LikeServiceProvider"
  1. Migrate the database from the command line:
php artisan migrate

Publishing the config file

Publishing the config file is optional:

php artisan vendor:publish --provider="Manzadey\LaravelLike\LikeServiceProvider" --tag="config"

Models

Your User model should import the Likeability trait, LikeabilityContract implements interface and use it, that trait allows the user to like the models. (see an example below):

use Manzadey\LaravelLike\Traits\Likeability;
use Manzadey\LaravelLike\Contracts\LikeabilityContract;

class User extends Authenticatable implements LikeabilityContract;
{
	use Likeability;
}

Your models should import the Likeable trait, LikeableContract implements interface and use it, that trait has the methods that you'll use to allow the model be likeable. In all the examples I will use the Post model as the model that is 'Likeable', that's for example proposes only. (see an example below):

use Manzadey\LaravelLike\Traits\Likeable;
use Manzadey\LaravelLike\Contracts\LikeableContract;

class Post extends Model implements LikeableContract
{
    use Likeable;
}

That's it ... your model is now "likeable"! Now the User can favorite models that have the favoriteable trait.

Usage

A standard set of methods for working with the package:

$article = \App\Models\Article::first();
$user = \App\Models\User::first();

$article->like($user); // Add the current model to like of the specified user
$article->dislike($user); // Add the current model to dislike of the specified user
$article->toggleLike($user); // The switch of the likes of the specified user
$article->removeLikeable($user); // Delete the current module from the likes of the specified user
$article->isLike($user); // Check the current model whether it is a likes of the specified user
$article->isDislike($user); // Check the current model whether it is a likes of the specified user

You can also use these methods as a `Likeability' model.

Checking the model for the presence of likes/dislikes of a particular user

$article = \App\Models\Article::first();
$user = \App\Models\User::first();

$article->isLike($user);
$article->isDislike($user);

You can also use these methods as a `Likeability' model.

Check the current model, whether it is marked with a like/dislike

$article = \App\Models\Article::first();

$article->isLikes();
$article->isDislikes();

Returns a collection of users who have liked/disliked this model

$article = \App\Models\Article::first();
$user = \App\Models\User::first();

$article->likeBy();
$article->dislikeBy();

We get a collection of models marked with a like/dislike

$article = \App\Models\Article::first();
$user = \App\Models\User::first();

$user->getLike();
$user->getDisike();

// With usage models
$user->getLike([\App\Models\Article::class]);
$user->getDisike([\App\Models\Article::class]);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email andrey.manzadey@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固