承接 kilobyteno/laravel-user-guest-like 相关项目开发

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

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

kilobyteno/laravel-user-guest-like

最新稳定版本:1.4.0

Composer 安装命令:

composer require kilobyteno/laravel-user-guest-like

包简介

A Laravel package to allow guests and users to like models

README 文档

README

Latest Version on Packagist Total Downloads Tests

A Laravel package to allow guests and users to like models.

Installation

You can install the package via composer:

composer require kilobyteno/laravel-user-guest-like

Publish the package:

php artisan vendor:publish --provider="Kilobyteno\LaravelUserGuestLike\LaravelUserGuestLikeServiceProvider"

Or you can publish manually:

php artisan vendor:publish --tag="user-guest-like-config"
php artisan vendor:publish --tag="user-guest-like-migrations"
php artisan migrate

The content of the config file that will be published to config/user-guest-like.php:

return [

    // Let guests like a model
    'guest_like_enabled' => true,

    // Save IP and user agent to database
    'user_tracking_enabled' => false,

];

Usage

Add the HasUserGuestLike trait to the model:

use Kilobyteno\LaravelUserGuestLike\Traits\HasUserGuestLike;
use Illuminate\Database\Eloquent\Model;

class EloquentModel extends Model
{
    use HasUserGuestLike;
}

Like a model as user (or guest):

$user = auth()->check() ? auth()->user() : null;
// Passing the user as null will like as a guest (if enabled)
$model->like($user);

Dislike a model as user (or guest):

$user = auth()->check() ? auth()->user() : null;
// Passing the user as null will like as a guest (if enabled)
$model->dislike($user);

Check if a user has liked a model (or guest has liked a model):

$user = auth()->check() ? auth()->user() : null;
// Passing the user as null will check if the guest (if enabled) has liked the model
if($model->hasLiked($user)) {
    // User has liked the model
}

Display the number of likes for a model:

$model->likes()->count();

Testing

composer test

Compatibility

1.0 1.1 1.2 1.3 1.4
8.x
9.x
10.x
11.x
12.x

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

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