akiyamaSM / laravel-followers

Gives Eloquent models the ability to manage followers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel 5 Followers

Build Status Code Climate Test Coverage Total Downloads Version Software License

Gives Eloquent models the ability to manage their followers.

##Models can:

  • Send Follow Requests
  • Accept Follow Requests
  • Deny Follow Requests
  • Block Another Model

Installation

First, install the package through Composer.

composer require skybluesofa/laravel-followers

Then include the service provider inside config/app.php.

'providers' => [
    ...
    Skybluesofa\Followers\ServiceProvider::class,
    ...
];

Publish config and migrations

php artisan vendor:publish --provider="Skybluesofa\Followers\ServiceProvider"

Configure the published config in

config\followers.php

Finally, migrate the database

php artisan migrate

Setup a Model

use Skybluesofa\Followers\Traits\Followable;
class User extends Model
{
    use Followable;
    ...
}

How to use

Check the Test file to see the package in action

Send a Follow Request

$user->follow($recipient);

Accept a Follow Request

$recipient->acceptFollowRequestFrom($user);

Check if User can follow Recipient

$user->canFollow($recipient);

Deny a Follow Request

$recipient->denyFollowRequestFrom($user);

Remove Follow

$user->unfollow($recipient);

Block a User

$user->blockBeingFollowedBy($recipient);

Unblock a User

$user->unblockBeingFollowedBy($recipient);

Check if User is Following another User

$user->isFollowing($recipient);

Check if User is being Followed by another User

$recipient->isFollowedBy($user);

Check if User has a pending Follow request from another User

$recipient->hasFollowRequestFrom($user);

Check if User sent a pending Follow request to another User

$user->hasSentFollowRequestTo($recipient);

Check if User has blocked another User

$recipient->hasBlockedBeingFollowedBy($user);

Check if User is blocked by another User

$user->isBlockedFromFollowing($recipient);

Get a single friendship

$user->getFollowing($recipient);

Get a list of all Friendships

$user->getFollowingList();

Get a list of all Friendships Paginated

$user->getFollowingList($per_page = 20);

Get Accepted Requests to follow

$user->getAcceptedRequestsToFollow();

Get Pending Requests to follow

$user->getPendingRequestsRequestsToFollow();

Get Denied Requests to follow

$user->getDeniedRequestsToFollow();

Get Blocked Requests to follow

$user->getBlockedFollowing();

Get a list of Following

$user->getAllFollowing();

Get a list of blocked Friendships

$user->getBlockedFriendships();

Get the number of Friends

$user->getFollowingCount();

Friends

To get a collection of friend models (ex. User) use the following methods:

Get Friends Following

$user->following();

Thank you

The basis of this code was garnered from https://github.com/hootlex/laravel-friendships. Although it was a jumping off point, much of the code has been rewritten to allow for Following as opposed to Mutual Friendship.

Contributing

See the CONTRIBUTING guide.

About

Gives Eloquent models the ability to manage followers.

License:MIT License


Languages

Language:PHP 100.0%