All Projects → hootlex → Laravel Friendships

hootlex / Laravel Friendships

Licence: mit
This package gives Eloquent models the ability to manage their friendships.

Projects that are alternatives of or similar to Laravel Friendships

Laravel Translatable
A Laravel package for multilingual models
Stars: ✭ 624 (-4.15%)
Mutual labels:  eloquent, laravel
Laravel Mongodb
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
Stars: ✭ 5,860 (+800.15%)
Mutual labels:  eloquent, laravel
Laravel Model Status
Easily add statuses to your models
Stars: ✭ 510 (-21.66%)
Mutual labels:  eloquent, laravel
Laravel Moderation
A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.
Stars: ✭ 487 (-25.19%)
Mutual labels:  eloquent, laravel
Laracsv
A Laravel package to easily generate CSV files from Eloquent model
Stars: ✭ 583 (-10.45%)
Mutual labels:  eloquent, laravel
Squire
A library of static Eloquent models for common fixture data.
Stars: ✭ 496 (-23.81%)
Mutual labels:  eloquent, laravel
Compoships
Multi-columns relationships for Laravel's Eloquent ORM
Stars: ✭ 537 (-17.51%)
Mutual labels:  eloquent, laravel
Laravel Model Cleanup
Clean up unneeded records
Stars: ✭ 388 (-40.4%)
Mutual labels:  eloquent, laravel
Laravel Ban
Laravel Ban simplify blocking and banning Eloquent models.
Stars: ✭ 572 (-12.14%)
Mutual labels:  eloquent, laravel
Laravel Model States
State support for models
Stars: ✭ 559 (-14.13%)
Mutual labels:  eloquent, laravel
Laravel Medialibrary
Associate files with Eloquent models
Stars: ✭ 4,743 (+628.57%)
Mutual labels:  eloquent, laravel
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (-8.45%)
Mutual labels:  eloquent, laravel
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (-34.87%)
Mutual labels:  eloquent, laravel
Laravel Cascade Soft Deletes
Cascading deletes for Eloquent models that implement soft deletes
Stars: ✭ 498 (-23.5%)
Mutual labels:  eloquent, laravel
Laravel Wallet
Easy work with virtual wallet
Stars: ✭ 401 (-38.4%)
Mutual labels:  eloquent, laravel
Laravel Eloquent Query Cache
Adding cache on your Laravel Eloquent queries' results is now a breeze.
Stars: ✭ 529 (-18.74%)
Mutual labels:  eloquent, laravel
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (-42.4%)
Mutual labels:  eloquent, laravel
Laravel Eloquent Uuid
A simple drop-in solution for providing UUID support for the IDs of your Eloquent models.
Stars: ✭ 388 (-40.4%)
Mutual labels:  eloquent, laravel
Laravel Mediable
Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel 5.
Stars: ✭ 541 (-16.9%)
Mutual labels:  eloquent, laravel
Laravel Schemaless Attributes
Add schemaless attributes to Eloquent models
Stars: ✭ 595 (-8.6%)
Mutual labels:  eloquent, laravel

Laravel 5 Friendships

Build Status Code Climate Test Coverage Total Downloads Version Software License Join the chat at https://gitter.im/laravel-friendships/Lobby

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 hootlex/laravel-friendships

If you are using Laravel < 5.5, you need to add Hootlex\Friendships\FriendshipsServiceProvider to your config/app.php providers array:

Hootlex\Friendships\FriendshipsServiceProvider::class,

Publish config and migrations

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

Configure the published config in

config\friendships.php

Finally, migrate the database

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

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
friendships.sent When a friend request is sent
friendships.accepted When a friend request is accepted
friendships.denied When a friend request is denied
friendships.blocked When a friend is blocked
friendships.unblocked When a friend is unblocked
friendships.cancelled When a friendship is cancelled

Contributing

See the CONTRIBUTING guide.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].