定制 tafadzwa/socialbeings 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tafadzwa/socialbeings

最新稳定版本:v1.0.0

Composer 安装命令:

composer require tafadzwa/socialbeings

包简介

This is my package socialbeings

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A powerful and flexible package designed to streamline and enhance user engagement within your Laravel applications. This package provides seamless integration for features such as likes, favorites, subscriptions, and follows, allowing you to easily implement and manage user interactions.

Key Features

  • Likes: Enable users to express their appreciation for content.
  • Favorites: Allow users to save and revisit their preferred items.
  • Subscriptions: Keep users updated with the latest content through notifications.
  • Follows: Facilitate user connections and community building.

Elevate your application’s functionality and keep your users engaged with our comprehensive solution!

Installation

You can install the package via composer:

composer require tafadzwa/socialbeings

You can publish and run the migrations with:

php artisan vendor:publish --tag="socialbeings-migrations"
php artisan migrate

You can publish the config file with:s

php artisan vendor:publish --tag="socialbeings-config"

This is the contents of the published config file:

return [
    'use_uuids' => false, // Default to false, can be set to true by the user

    'user_table' => env('USER_TABLE', 'users'), // Default to 'users'
];

Following

You can follow any model by using import the CanFollow Trait which enable a trait to follow another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use TafadzwaLawrence\SocialBeings\Traits\CanFollow;

class User extends Authenticatable
{
    use CanFollow;
    // Other model properties and methods...
}

Then the model you want to follow add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use TafadzwaLawrence\SocialBeings\Traits\Followable;

class Post extends Model
{
    use Followable;

    // Other model properties and methods...
}

Use Cases

    $user = User::find(1);
    $post = Post::find(1);

    $user->follow($post);
    $user->unfollow($post);
    $user->isFollowedBy($post);

    $post->followers(); //Retrieve all the followers
    $post->getFollowersCountAttribute();  // Count the number of followers
    $post->getFormattedFollowersCountAttribute();  // Formats using 10K if count is > 1000

Likes

You can like any model by using import the CanFollow Trait which enable a trait to follow another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use TafadzwaLawrence\SocialBeings\Traits\CanLike;

class User extends Authenticatable
{
    use CanLike;
    // Other model properties and methods...
}

Then the model you want to follow add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use TafadzwaLawrence\SocialBeings\Traits\Likeable;

class Post extends Model
{
    use Likeable;

    // Other model properties and methods...
}

Use case

    $user = User::find(1);
    $post = Post::find(1);

    $user->like($post);
    $post->unlike($user->id);
    $post->isLikedBy($user->id)

Favourites

You can favor any model by using import the CanFavor Trait which enable a trait to favor another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use TafadzwaLawrence\SocialBeings\Traits\CanFavor;

class User extends Authenticatable
{
    use CanFavor;
    // Other model properties and methods...
}

Then the model you want to favour add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use TafadzwaLawrence\SocialBeings\Traits\Favourable;

class Post extends Model
{
    use Favourable;

    // Other model properties and methods...
}

Use case

    $user = User::find(1);
    $post = Post::find(1);

    $user->favour($post);
    $post->unfavour($user->id);
    $post->isFavouredBy($user->id)

    $post->favorites;
    $post->favorites_count; // K format for > 1000 favourites

Subscriptions

You can favour any model by using import the CanFavor Trait which enable a trait to follow another model

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use TafadzwaLawrence\SocialBeings\Traits\CanSubscribe;

class User extends Authenticatable
{
    use CanSubscribe;
    // Other model properties and methods...
}

Then the model you want to favour add the following trait

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use TafadzwaLawrence\SocialBeings\Traits\Subscribable;

class Post extends Model
{
    use Subscribable;

    // Other model properties and methods...
}

Use case

    $user = User::find(1);
    $post = Post::find(1);

    $user->subscribe($post);
    $post->unsubscribe($user->id);
    $post->isSubscribedBy($user->id)

    $post->subscriptions;
    $post->subscribers_count; // K format for > 1000 favourites

Testing

composer test

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.

统计信息

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

GitHub 信息

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

其他信息

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