PHPackages                             shababsoftwares/laravel-friendships - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. shababsoftwares/laravel-friendships

ActiveLibrary[Framework](/categories/framework)

shababsoftwares/laravel-friendships
===================================

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

v1.0(2y ago)44MITPHPPHP &gt;=7.3

Since Jan 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ShababSoftwares/Laravel-Friendships)[ Packagist](https://packagist.org/packages/shababsoftwares/laravel-friendships)[ RSS](/packages/shababsoftwares-laravel-friendships/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel 8 Friendships Package
=============================

[](#laravel-8-friendships-package)

[![Downloads](https://camo.githubusercontent.com/e2280e6a9f50d3e25f3ff3e4ea874c776cf75a064ca41ae92aaa77ecf0e4ad42/68747470733a2f2f706f7365722e707567782e6f72672f536861626162536f667477617265732f4c61726176656c2d467269656e6473686970732f642f746f74616c2e737667)](https://github.com/ShababSoftwares/Laravel-Friendships)[![License](https://camo.githubusercontent.com/2882e7634062013b21b5669cf9c1a697aefb768ddaabde10b38202217f894332/68747470733a2f2f706f7365722e707567782e6f72672f536861626162536f667477617265732f4c61726176656c2d467269656e6473686970732f6c6963656e73652e737667)](LICENSE.md)

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

Models can:
-----------

[](#models-can)

- Send Friend Requests
- Accept Friend Requests
- Deny Friend Requests
- Block Another Model
- Group Friends

Installation
------------

[](#installation)

First, install the package through Composer.

```
composer require shababsoftwares/laravel-friendships
```

Publish config and migrations

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

```

Configure the published config in

```
config\friendships.php

```

Finally, migrate the database

```
php artisan migrate

```

Setup a Model
-------------

[](#setup-a-model)

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

How to use
----------

[](#how-to-use)

[Check the Test file to see the package in action](https://github.com/ShababSoftwares/Laravel-Friendships/blob/master/tests/FriendshipsTest.php)

#### Send a Friend Request

[](#send-a-friend-request)

```
$user->befriend($recipient);
```

#### Accept a Friend Request

[](#accept-a-friend-request)

```
$user->acceptFriendRequest($sender);
```

#### Deny a Friend Request

[](#deny-a-friend-request)

```
$user->denyFriendRequest($sender);
```

#### Remove Friend

[](#remove-friend)

```
$user->unfriend($friend);
```

#### Block a Model

[](#block-a-model)

```
$user->blockFriend($friend);
```

#### Unblock a Model

[](#unblock-a-model)

```
$user->unblockFriend($friend);
```

#### Check if Model is Friend with another Model

[](#check-if-model-is-friend-with-another-model)

```
$user->isFriendWith($friend);
```

#### Check if Model has a pending friend request from another Model

[](#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

[](#check-if-model-has-already-sent-a-friend-request-to-another-model)

```
$user->hasSentFriendRequestTo($recipient);
```

#### Check if Model has blocked another Model

[](#check-if-model-has-blocked-another-model)

```
$user->hasBlocked($friend);
```

#### Check if Model is blocked by another Model

[](#check-if-model-is-blocked-by-another-model)

```
$user->isBlockedBy($friend);
```

#### Get a single friendship

[](#get-a-single-friendship)

```
$user->getFriendship($friend);
```

#### Get a list of all Friendships

[](#get-a-list-of-all-friendships)

```
$user->getAllFriendships();
```

#### Get a list of pending Friendships

[](#get-a-list-of-pending-friendships)

```
$user->getPendingFriendships();
```

#### Get a list of accepted Friendships

[](#get-a-list-of-accepted-friendships)

```
$user->getAcceptedFriendships();
```

#### Get a list of denied Friendships

[](#get-a-list-of-denied-friendships)

```
$user->getDeniedFriendships();
```

#### Get a list of blocked Friendships

[](#get-a-list-of-blocked-friendships)

```
$user->getBlockedFriendships();
```

#### Get a list of pending Friend Requests

[](#get-a-list-of-pending-friend-requests)

```
$user->getFriendRequests();
```

#### Get the number of Friends

[](#get-the-number-of-friends)

```
$user->getFriendsCount();
```

#### Get the number of Pendings

[](#get-the-number-of-pendings)

```
$user->getPendingsCount();
```

#### Get the number of mutual Friends with another user

[](#get-the-number-of-mutual-friends-with-another-user)

```
$user->getMutualFriendsCount($otherUser);
```

Friends
-------

[](#friends)

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

#### Get Friends

[](#get-friends)

```
$user->getFriends();
```

#### Get Friends Paginated

[](#get-friends-paginated)

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

#### Get Friends of Friends

[](#get-friends-of-friends)

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

#### Collection of Friends in specific group paginated:

[](#collection-of-friends-in-specific-group-paginated)

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

#### Get mutual Friends with another user

[](#get-mutual-friends-with-another-user)

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

#### Get friends using advanced paginated and scoped status

[](#get-friends-using-advanced-paginated-and-scoped-status)

```
// Methods usages (Status available: pending, denied, blocked and accepted.) (Paginators available: none, default, simple)
$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
-------------

[](#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

[](#group-a-friend)

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

#### Remove a Friend from family group

[](#remove-a-friend-from-family-group)

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

#### Remove a Friend from all groups

[](#remove-a-friend-from-all-groups)

```
$user->ungroupFriend($friend);
```

#### Get the number of Friends in specific group

[](#get-the-number-of-friends-in-specific-group)

```
$user->getFriendsCount($group_name);
```

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

[](#to-filter-friendships-by-group-you-can-pass-a-group-slug)

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

Events
------

[](#events)

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

Event nameFiredShababSoftwares\\Friendships\\Events\\SentWhen a friend request is sentShababSoftwares\\Friendships\\Events\\AcceptedWhen a friend request is acceptedShababSoftwares\\Friendships\\Events\\DeniedWhen a friend request is deniedShababSoftwares\\Friendships\\Events\\BlockedWhen a friend is blockedShababSoftwares\\Friendships\\Events\\UnblockedWhen a friend is unblockedShababSoftwares\\Friendships\\Events\\CancelledWhen a friendship is cancelledLicense
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

Shabab Softwares
----------------

[](#shabab-softwares)

[www.shababsoftwares.com](https://www.shababsoftwares.com)

Shabab Softwares (c) 2024

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

844d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fed09186c271349756a4d066772e2448ccffa79a2afa6a1f1b98dfe72d131e6e?d=identicon)[shababsoftwares](/maintainers/shababsoftwares)

---

Top Contributors

[![ml-arifshabab](https://avatars.githubusercontent.com/u/158835119?v=4)](https://github.com/ml-arifshabab "ml-arifshabab (4 commits)")

---

Tags

chatcirclefriendfriendshipgrouplaravelmessagemutualmessagephpframeworklaravelchatgroupfriendfriendshipcirclemutual

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shababsoftwares-laravel-friendships/health.svg)

```
[![Health](https://phpackages.com/badges/shababsoftwares-laravel-friendships/health.svg)](https://phpackages.com/packages/shababsoftwares-laravel-friendships)
```

###  Alternatives

[pestphp/pest-plugin-laravel

The Pest Laravel Plugin

22044.1M8.0k](/packages/pestphp-pest-plugin-laravel)[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)[dragon-code/support

Support package is a collection of helpers and tools for any project.

238.7M101](/packages/dragon-code-support)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[gdg-tangier/cloud-pubsub

Google Cloud pub-sub for laravel

5054.9k](/packages/gdg-tangier-cloud-pubsub)[jonpurvis/squeaky

A Laravel Validation Rule to Help Catch Profanity.

706.0k](/packages/jonpurvis-squeaky)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
