hareku / laravel-follow
This package is abandoned and no longer maintained.
No replacement package was suggested.
Laravel 5 user follow system
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
This package helps you to add user follow system to your project.
- So simply and easy.
- Use "ON DELETE CASCADE" in follow relationships table.
Require
- Support Laravel 5.4~
- Required php >=7.0 (v1.* >=5.6.4)
Installation
First, pull in the package through Composer.
Run composer require hareku/laravel-follow
And then, include the service provider within config/app.php
.
'providers' => [ Hareku\LaravelFollow\FollowServiceProvider::class, ];
Publish the config file. (follow.php)
$ php artisan vendor:publish --provider="Hareku\LaravelFollow\FollowServiceProvider"
Finally, use Followable trait in User model.
use Hareku\LaravelFollow\Traits\Followable; class User extends Model { use Followable; }
Usage
Follow a user or users
$user->follow(1); $user->follow([1,2,3,4]);
Add followers
$user->addFollowers(1); $user->addFollowers([1,2,3,4]);
Unfollow a user or users
$user->unfollow(1); $user->unfollow([1,2,3,4]);
Get followers / followees
// followers $user->followers()->get(); // Get follower user models. $user->followerRelationships()->get(); // Get follower relationship models. // followees $user->followees()->get(); $user->followeeRelationships()->get();
Check if follow
$user->isFollowing(1); $user->isFollowing([1,2,3,4]);
Check if followed by
$user->isFollowedBy(1); $user->isFollowedBy([1,2,3,4]);
Check if mutual follow
$user->isMutualFollow(1); $user->isMutualFollow([1,2,3,4]);
Get follower/followee IDs
$user->follow([1,2,3]); $user->followerIds(); // [1,2,3] $user->followeeIds();
Reject user ids
$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]
License
MIT
Author
hareku (hareku908@gmail.com)