Giter Club home page Giter Club logo

laravel-followers's Introduction

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

Methods

Send a Follow Request

Will trigger a Skybluesofa\LaravelFollowers\Events\FollowRequest event.

$user->follow($recipient);

Accept a Follow Request

Will trigger a Skybluesofa\LaravelFollowers\Events\FollowRequestAccepted event.

$recipient->acceptFollowRequestFrom($user);

Deny a Follow Request

Will trigger a Skybluesofa\LaravelFollowers\Events\FollowRequestDenied event.

$recipient->denyFollowRequestFrom($user);

Remove Follow

Will trigger a Skybluesofa\LaravelFollowers\Events\Unfollow event.

$user->unfollow($recipient);

Block a User

Will trigger a Skybluesofa\LaravelFollowers\Events\FollowingBlocked event.

$user->blockBeingFollowedBy($recipient);

Unblock a User

Will trigger a Skybluesofa\LaravelFollowers\Events\FollowingUnblocked event.

$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->getFriendship($recipient);

Get a list of all Friendships

$user->getAllFriendships();

Get a list of pending Friendships

$user->getPendingFriendships();

Get a list of accepted Friendships

$user->getAcceptedFriendships();

Get a list of denied Friendships

$user->getDeniedFriendships();

Get a list of blocked Friendships

$user->getBlockedFriendships();

Get a list of pending Friend Requests

$user->getFriendRequests();

Get the number of Friends

$user->getFriendsCount();

Friends

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

Get Friends

$user->getFriends();

Get Friends Paginated

$user->getFriends($perPage = 20);

Events

These events are triggered during the lifecycle of following/unfollowing/accept/deny followers:

Skybluesofa\LaravelFollowers\Events\FollowingBlocked(Model $recipient, Model $sender);
Skybluesofa\LaravelFollowers\Events\FollowingUnblocked(Model $recipient, Model $sender);
Skybluesofa\LaravelFollowers\Events\FollowRequest(Model $recipient, Model $sender);
Skybluesofa\LaravelFollowers\Events\FollowRequestAccepted(Model $recipient, Model $sender);
Skybluesofa\LaravelFollowers\Events\FollowRequestDenied(Model $recipient, Model $sender);
Skybluesofa\LaravelFollowers\Events\Unfollow(Model $recipient, Model $sender);

To listen for and react to these events, follow the instructions available in the Laravel Documentation.

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.

laravel-followers's People

Contributors

acekyd avatar akiyamasm avatar skybluesofa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-followers's Issues

Clean up README

The README.md file needs to be reviewed and updated:

  • Reflecting the current terminology
  • Ensure that all available methods are docuemented

no files are being published

I am running php artisan vendor:publish --provider="Skybluesofa\Followers\ServiceProvider"
It says publishing complete, but no files are being published

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.