hareku / laravel-follow
此包已被废弃且不再维护。没有建议的替代包。
Laravel 5 用户关注系统
3.0.0
2017-05-30 01:29 UTC
Requires
- php: >=7.0
- illuminate/database: 5.4.*
- illuminate/support: 5.4.*
- nesbot/carbon: ~1.22
Requires (Dev)
- phpunit/phpunit: ~5.7
This package is not auto-updated.
Last update: 2020-11-04 01:28:29 UTC
README
此包可以帮助您将用户关注系统添加到项目中。
- 简单易用。
- 在关注关系表中使用 "ON DELETE CASCADE"。
要求
- 支持 Laravel 5.4~
- 所需 php >=7.0 (v1.* >=5.6.4)
安装
首先,通过 Composer 引入包。
运行 composer require hareku/laravel-follow
然后,在 config/app.php
中包含服务提供者。
'providers' => [ Hareku\LaravelFollow\FollowServiceProvider::class, ];
发布配置文件。(follow.php)
$ php artisan vendor:publish --provider="Hareku\LaravelFollow\FollowServiceProvider"
最后,在 User 模型中使用 Followable 特性。
use Hareku\LaravelFollow\Traits\Followable; class User extends Model { use Followable; }
使用方法
关注用户或多个用户
$user->follow(1); $user->follow([1,2,3,4]);
添加关注者
$user->addFollowers(1); $user->addFollowers([1,2,3,4]);
取消关注用户或多个用户
$user->unfollow(1); $user->unfollow([1,2,3,4]);
获取关注者/被关注者
// followers $user->followers()->get(); // Get follower user models. $user->followerRelationships()->get(); // Get follower relationship models. // followees $user->followees()->get(); $user->followeeRelationships()->get();
检查是否关注
$user->isFollowing(1); $user->isFollowing([1,2,3,4]);
检查是否被关注
$user->isFollowedBy(1); $user->isFollowedBy([1,2,3,4]);
检查是否相互关注
$user->isMutualFollow(1); $user->isMutualFollow([1,2,3,4]);
获取关注者/被关注者 ID
$user->follow([1,2,3]); $user->followerIds(); // [1,2,3] $user->followeeIds();
拒绝用户 ID
$user->follow([1,2,3]); $user->rejectNotFollowee([1,2,3,4,5]); // [1,2,3]
$user->followers()->pluck('id')->all(); // [1,2,3] $user->rejectNotFollower([1,2,3,4,5]); // [1,2,3]
许可证
MIT
作者
hareku (hareku908@gmail.com)