PHPackages                             somecv/laravel-friends - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. somecv/laravel-friends

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

somecv/laravel-friends
======================

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

04PHP

Since Jun 13Pushed 3y agoCompare

[ Source](https://github.com/somecv/laravel-friends)[ Packagist](https://packagist.org/packages/somecv/laravel-friends)[ RSS](/packages/somecv-laravel-friends/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#laravel-8-friendships)

[![Build Status](https://camo.githubusercontent.com/c86158c08a9abed1b4ec915e513303e43e00d8c0729a2acf8896580c1b83c6a7/68747470733a2f2f7472617669732d63692e6f72672f63756974636f64652f6c61726176656c2d667269656e6473686970732e7376673f6272616e63683d76312e302e3231)](https://travis-ci.org/cuitcode/laravel-friendships) [![Code Climate](https://camo.githubusercontent.com/f785afbdfc407a3ea34e757e07c0b65280900e469d5ef4c56c96e3a79422cdb1/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f63756974636f64652f6c61726176656c2d667269656e6473686970732f6261646765732f6770612e737667)](https://codeclimate.com/github/cuitcode/laravel-friendships) [![Test Coverage](https://camo.githubusercontent.com/5919a2dfa9bcb2cebb57fc955556485a51c42f27ec2c9aac92caaaafebeafc62/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f63756974636f64652f6c61726176656c2d667269656e6473686970732f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/cuitcode/laravel-friendships/coverage) [![Total Downloads](https://camo.githubusercontent.com/6602c420b1a08df39e772850723f7ec992706d1e0ee3fe7f6fe9ba8f6cea9602/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63756974636f64652f6c61726176656c2d667269656e6473686970732e7376673f7374796c653d666c6174)](https://packagist.org/packages/cuitcode/laravel-friendships) [![Version](https://camo.githubusercontent.com/861c34cad6ea0f06aa892c4b413ef6c55b107498a2702fa3636848f9d1d51954/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63756974636f64652f6c61726176656c2d667269656e6473686970732e7376673f7374796c653d666c6174)](https://packagist.org/packages/cuitcode/laravel-friendships) [![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE) [![Join the chat at https://gitter.im/laravel-friendships/Lobby](https://camo.githubusercontent.com/d3957ab46060d556a01935edc54cb02907b1a65433e47ea04716a6427fe54a40/68747470733a2f2f6261646765732e6769747465722e696d2f6c61726176656c2d667269656e6473686970732f4c6f6262792e737667)](https://gitter.im/laravel-friendships/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

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 cuitcode/laravel-friendships
```

If you are using Laravel &lt; 5.5, you need to add Cuitcode\\Friendships\\FriendshipsServiceProvider to your `config/app.php` providers array:

```
Cuitcode\Friendships\FriendshipsServiceProvider::class,
```

Publish config and migrations

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

```

Configure the published config in

```
config\friendships.php

```

Finally, migrate the database

```
php artisan migrate

```

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

[](#setup-a-model)

```
use Cuitcode\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/cuitcode/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);
```

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 nameFiredfriendships.sentWhen a friend request is sentfriendships.acceptedWhen a friend request is acceptedfriendships.deniedWhen a friend request is deniedfriendships.blockedWhen a friend is blockedfriendships.unblockedWhen a friend is unblockedfriendships.cancelledWhen a friendship is cancelledContributing
------------

[](#contributing)

See the [CONTRIBUTING](CONTRIBUTING.md) guide.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity25

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.

### Community

Maintainers

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

---

Top Contributors

[![natecorkish](https://avatars.githubusercontent.com/u/66919946?v=4)](https://github.com/natecorkish "natecorkish (2 commits)")

### Embed Badge

![Health badge](/badges/somecv-laravel-friends/health.svg)

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

###  Alternatives

[freshbitsweb/laratables

Ajax support of DataTables for Laravel

4871.1M3](/packages/freshbitsweb-laratables)[ahand/mobileesp

Since 2008, MobileESP provides web site developers an easy-to-use and lightweight API for detecting whether visitors are using a mobile device, and if so, what kind. The APIs provide simple boolean results ('true' or 'false') for identifying individual device categories (such as iPhone, BlackBerry, Android, and Windows Mobile), device capabilities (e.g., J2ME), and broad classes of devices, such as 'iPhone Tier' (iPhone/Android/Tizen) or 'Tablet Tier.' APIs are available in PHP, JavaScript, Java, C#, Ruby Python, and more.

174491.4k7](/packages/ahand-mobileesp)

PHPackages © 2026

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