Giter Club home page Giter Club logo

laravel-friendships's Introduction

Laravel 6 Friendships Package

Build Status codecov Code Climate Total Downloads Version Software License

--

This repository is currently a copy and backup of Demency/laravel-friendships (which has been removed). I plan on supporting the package going forward.

--

This package gives Eloquent 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
  • Group Friends

Installation

First, install the package through Composer.

composer require n3rdp1um23/laravel-friendships

Publish config and migrations

php artisan vendor:publish --provider="N3rdP1um23\Friendships\FriendshipsServiceProvider"

Configure the published config in

config\friendships.php

Finally, migrate the database

php artisan migrate

Setup a Model

use N3rdP1um23\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($sender);

Deny a Friend Request

$user->denyFriendRequest($sender);

Remove Friend

$user->unfriend($friend);

Block a Model

$user->blockFriend($friend);

Unblock a Model

$user->unblockFriend($friend);

Check if Model is Friend with another Model

$user->isFriendWith($friend);

Check if Model has a pending friend request from another Model

$user->hasFriendRequestFrom($sender);

Check if Model has already sent a friend request to another Model

$user->hasSentFriendRequestTo($recipient);

Check if Model has blocked another Model

$user->hasBlocked($friend);

Check if Model is blocked by another Model

$user->isBlockedBy($friend);

Get a single friendship

$user->getFriendship($friend);

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();

Get the number of Pendings

$user->getPendingsCount();

Get the number of mutual Friends with another user

$user->getMutualFriendsCount($otherUser);

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);

Get Friends of Friends

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

Collection of Friends in specific group paginated:

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

Get mutual Friends with another user

$user->getMutualFriends($otherUser, $perPage = 20);

Get friends using advanced paginated and scoped status

// Methods usages (Status available: pending, denied, blocked and accepted.)
$user->{status}Friends($resultsPerPage = 0, $paginationType = 'none');

// Example #1: (Get accepted friends using default paginator with 25 results per page).
$user->acceptedFriends(25, 'default');

// Example #2: (Get pending friends using simple paginator with 10 results per page).
$user->pendingFriends(10, 'simple');

// Example #3: (Get all denied friends without pagination).
$user->deniedFriends();

// Example #3: (Get denied friends using default paginator with 30 results per page).
$user->blockedFriends(30);

Friend groups

The friend groups are defined in the config/friendships.php file. The package comes with a few default groups. To modify them, or add your own, you need to specify a slug and a key.

// config/friendships.php
...
'groups' => [
    'acquaintances' => 0,
    'close_friends' => 1,
    'family' => 2
]

Since you've configured friend groups, you can group/ungroup friends using the following methods.

Group a Friend

$user->groupFriend($friend, $group_name);

Remove a Friend from family group

$user->ungroupFriend($friend, 'family');

Remove a Friend from all groups

$user->ungroupFriend($friend);

Get the number of Friends in specific group

$user->getFriendsCount($group_name);

To filter friendships by group you can pass a group slug.

$user->getAllFriendships($group_name);
$user->getAcceptedFriendships($group_name);
$user->getPendingFriendships($group_name);
...

Events

This is the list of the events fired by default for each action

Event name Fired
N3rdP1um23\Friendships\Events\Sent When a friend request is sent
N3rdP1um23\Friendships\Events\Accepted When a friend request is accepted
N3rdP1um23\Friendships\Events\Denied When a friend request is denied
N3rdP1um23\Friendships\Events\Blocked When a friend is blocked
N3rdP1um23\Friendships\Events\Unblocked When a friend is unblocked
N3rdP1um23\Friendships\Events\Cancelled When a friendship is cancelled

Contributing

See the CONTRIBUTING guide.

laravel-friendships's People

Contributors

n3rdp1um23 avatar zen0x7 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

laravel-friendships's Issues

Question

Hey! @demency do you have any plans to support this package again?

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.