Code Monkey home page Code Monkey logo

laravel-friendships's Introduction

Laravel 5 Friendships Build Status Total Downloads Version Software License

This package gives Eloqent models the ability to manage their friendships. You can easily design a Facebook like Friend System.

##Models can:

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

Installation

First, install the package through Composer.

composer require hootlex/laravel-friendships

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

'providers' => [
    ...
    Hootlex\Friendships\FriendshipsServiceProvider::class,
    ...
];

Lastly you need to publish the migration and migrate the database

php artisan vendor:publish --provider="Hootlex\Friendships\FriendshipsServiceProvider" && php artisan migrate

Setup a Model

use Hootlex\Friendships\Traits\Friendable;
class User extends Model
{
    use Friendable;
    ...
}

How to use

Check the Test file to see the package in action

Send a Friend Request

$user->befriend($recipient);

Accept a Friend Request

$user->acceptFriendRequest($recipient);

Deny a Friend Request

$user->denyFriendRequest($recipient);

Remove Friend

$user->unfriend($recipient);

Block a Model

$user->blockFriend($recipient);

Unblock a Model

$user->unblockFriend($recipient);

Check if Model is Friend with another Model

$user->isFriendWith($recipient);

Check if Model has a pending friend request from another Model

$user->hasFriendRequestFrom($recipient);

Check if Model has blocked another Model

$user->hasBlocked($recipient);

Check if Model is blocked by another Model

$user->isBlockedBy($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();

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

Get Friends

$user->getFriends();

Get Friends Paginated

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

Get Friends of Friends

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

laravel-friendships's People

Contributors

hootlex avatar stephane-monnot avatar nilportugues avatar irazasyed avatar vedmant avatar arubacao avatar

Watchers

James Cloos avatar Evert R. avatar

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.