PHPackages                             arubacao/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. [Database &amp; ORM](/categories/database)
4. /
5. arubacao/friends

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

arubacao/friends
================

Manage Friends in Laravel

2.0.0(9y ago)131.1k5[1 issues](https://github.com/arubacao/friends/issues)MITPHPPHP &gt;=5.6.0

Since Jun 20Pushed 7y ago2 watchersCompare

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

READMEChangelogDependencies (5)Versions (4)Used By (0)

Unmaintained
============

[](#unmaintained)

This package is unmaintained and was only a quick hacking around. Don't use in production code.

Friends (Laravel 5 Package)
===========================

[](#friends-laravel-5-package)

[![Build Status](https://camo.githubusercontent.com/fc556f2aee9c553728620824276e70e36a2c3ad7439d771823809fab7069dc01/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f617275626163616f2f667269656e64732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/arubacao/friends)[![Latest Version](https://camo.githubusercontent.com/f9fe95818d2b61787a27197d018bb943c658b8ce38359e27ad83e5514a612de0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617275626163616f2f667269656e64732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arubacao/friends)[![SensioLabsInsight](https://camo.githubusercontent.com/8bcdc00c4c39f574e471fbc168179b9c91b9b0a28f4c217514a3a68aac9b271d/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f39633065393836632d343465302d343137642d626438632d3936656131373062636235302e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/9c0e986c-44e0-417d-bd8c-96ea170bcb50)[![Quality Score](https://camo.githubusercontent.com/7f2fcc5f38520e2b679c71dffe1b65712e2cd2869fcfb5823b876ba3a6e533fc/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f617275626163616f2f667269656e64732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/arubacao/friends)[![Code Coverage](https://camo.githubusercontent.com/dd68a34e802ca57de2bdbb19465ae8add49543a878f7aeca25de63bb3e3adfb7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f617275626163616f2f667269656e64732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/arubacao/friends/?branch=master)[![codecov](https://camo.githubusercontent.com/51bf682f020490f1f407a267e7e5f2af9e033ef3c6cec337ed4f025aa933ee8c/68747470733a2f2f636f6465636f762e696f2f67682f617275626163616f2f667269656e64732f6272616e63682f6d61737465722f67726170682f62616467652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/arubacao/friends)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Organise Friends and Relationships Between Users in Laravel and Lumen.
----------------------------------------------------------------------

[](#organise-friends-and-relationships-between-users-in-laravel-and-lumen)

#### Friends provides everything you need to easily implement your own Facebook like Friend System.

[](#friends-provides-everything-you-need-to-easily-implement-your-own-facebook-like-friend-system)

Users can:
----------

[](#users-can)

- Send Friend Requests
- Accept Friend Requests
- Deny Friend Requests
- Delete Friends

Contents
--------

[](#contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Friend Requests](#friend-requests)
        - [Send Friend Request](#send-friend-request)
        - [Accept Friend Request](#accept-friend-request)
        - [Deny Friend Request](#deny-friend-request)
    - [My Friends](#my-friends)
        - [Is Friend With](#is-friend-with)
        - [Delete Friend](#delete-friend)
        - [Retrieve Friends](#retrieve-friends)
        - [Retrieve Incoming Friends](#retrieve-incoming-friends)
        - [Retrieve Any Friends](#retrieve-any-friends)
    - [Relationships](#relationships)
        - [Has Relationship With](#has-relationship-with)
        - [Get Relationship With](#get-relationship-with)
        - [Has Pending Request From](#has-pending-request-from)
    - [Query Users Including Relationships](#query-users)
- [License](#license)

\## Installation For Laravel 5.\*
----------------

[](#for-laravel-5)

### Pull in Package with Composer

[](#pull-in-package-with-composer)

`composer require arubacao/friends`

### Register Service Provider

[](#register-service-provider)

Include the service provider inside `config/app.php`.

```
'providers' => [
    ...
    Arubacao\Friends\FriendsServiceProvider::class,
    ...
];
```

### Run Migrations

[](#run-migrations)

Publish the migration and migrate the database

```
php artisan vendor:publish --provider="Arubacao\Friends\FriendsServiceProvider"
php artisan migrate
```

After the migration, 1 new table will be created:

- `friends` — stores [relationships/friendships](http://laravel.com/docs/5.2/eloquent-relationships#many-to-many) between Users

The `vendor:publish` command will also create a `friends.php` file in your config directory.
The default configuration should work just fine for most applications.
Otherwise check out [Configuration](#configuration).

### Prepare User Model

[](#prepare-user-model)

Include `Friendable` Trait in `User` Model

```
use Arubacao\Friends\Traits\Friendable;

class User extends Model
{
    use Friendable; // Add this trait to your model
    ...
}
```

**And you are ready to go.**

\## Configuration ### Configuration File `friends.php` *(Optional)*

[](#configuration-file-friendsphp-optional)

Find `friends.php` in your config folder. Make sure you published the package beforehand.

- `user_model` — This is the applications `User` model used by Friends.
- `users_table` — This is the applications `users` table name used by Friends.

\## Usage \### Friend Requests \#### Send Friend Request ```php $user-&gt;sendFriendRequestTo($recipient); ``` `$user` must be instance of `User` `$recipient` must be instance of `User`, `User` array or integer (User id) \#### Accept Friend Request ```php $user-&gt;acceptFriendRequestFrom($sender); ``` `$user` must be instance of `User` `$sender` must be instance of `User`, `User` array or integer (User id) \#### Deny Friend Request ```php $user-&gt;denyFriendRequestFrom($sender); ``` `$user` must be instance of `User` `$sender` must be instance of `User`, `User` array or integer (User id) \### My Friends \#### Delete Friend ```php $user-&gt;deleteFriend($douchebag); ``` `$user` must be instance of `User` `$douchebag` must be instance of `User`, `User` array or integer (User id) \#### Retrieve Friends - Get all friends of a user - `status` is always `1` \*ACCEPTED\* ```
$friends = $user->friends();
```

`$user` must be instance of `User`

`$friends`:

```
[{
	"id": 3,
	"name": "harri121",
	"created_at": "2016-06-18 19:08:45",
	"updated_at": "2016-06-18 19:08:45",
	"pivot": {
		"sender_id": 1,
		"recipient_id": 3,
		"created_at": "2016-06-19 19:53:27",
		"updated_at": "2016-06-19 22:56:40",
		"status": 1
	}
}]
```

\#### Retrieve Incoming Friends - Get all users who send friend request to `$user` - `status` is always `0` \*PENDING\* - `recipient\_id` is always `id` of `$user` ```
$friends = $user->incoming_friends();
```

`$user` must be instance of `User`

`$friends`:

```
[{
	"id": 3,
	"name": "ejoebstl",
	"created_at": "2016-06-18 19:08:45",
	"updated_at": "2016-06-18 19:08:45",
	"pivot": {
		"sender_id": 3,
		"recipient_id": 1,
		"created_at": "2016-06-19 19:53:27",
		"updated_at": "2016-06-19 22:56:40",
		"status": 0
	}
}]
```

\#### Retrieve Any Friends \*\*Remember:\*\* &gt; Just like in the real life a 'friend' or 'friendship' can be anything, also negative ;) - Get all users who have any kind of friendship/relationship with `$user`

```
$friends = $user->any_friends();
```

`$user` must be instance of `User`

`$friends`:

```
[{
	"id": 3,
	"name": "harri121",
	"created_at": "2016-06-18 19:08:45",
	"updated_at": "2016-06-18 19:08:45",
	"pivot": {
		"sender_id": 1,
		"recipient_id": 3,
		"created_at": "2016-06-19 19:53:27",
		"updated_at": "2016-06-19 22:56:40",
		"status": 1
	}
},
{
	"id": 2,
	"name": "ejoebstl",
	"created_at": "2016-06-18 19:08:41",
	"updated_at": "2016-06-18 19:08:41",
	"pivot": {
		"recipient_id": 1,
		"sender_id": 2,
		"created_at": "2016-06-19 19:53:27",
		"updated_at": "2016-06-19 19:53:27",
		"status": 0
	}
}]
```

\### Relationships \#### Has Relationship With ```php $user-&gt;hasRelationshipWith($person, $status); ``` `$user` must be instance of `User` `$person` must be instance of `User`, `User` array or integer (User id) `$status` must be array of integers (`Status`) \#### Get Relationship With ```php $user-&gt;getRelationshipWith($person, $status); ``` `$user` must be instance of `User` `$person` must be instance of `User`, `User` array or integer (User id) `$status` must be array of integers (`Status`) \#### Has Pending Request From ```php $user-&gt;hasPendingRequestFrom($person); ``` `$user` must be instance of `User` `$person` must be instance of `User`, `User` array or integer (User id) \### Query Users Including Relationships ```
$users = \App\User::whereIn('id', [2,3,4])
      ->includeRelationshipsWith(1)
      ->get();
```

`$users`:

```
[{
	"id": 2,
	"name": "ejoebstl",
	"created_at": "2016-06-18 19:08:41",
	"updated_at": "2016-06-18 19:08:41",
	"friends_i_am_sender": [{
		"id": 1,
		"name": "arubacao",
		"created_at": "2016-06-18 19:08:35",
		"updated_at": "2016-06-18 19:08:35",
		"pivot": {
			"sender_id": 2,
			"recipient_id": 1,
			"created_at": "2016-06-19 19:53:27",
			"updated_at": "2016-06-19 19:53:27",
			"status": 0
		}
	}],
	"friends_i_am_recipient": []
},
{
	"id": 3,
	"name": "harri121",
	"created_at": "2016-06-18 19:08:45",
	"updated_at": "2016-06-18 19:08:45",
	"friends_i_am_sender": [],
	"friends_i_am_recipient": [{
		"id": 1,
		"name": "arubacao",
		"created_at": "2016-06-18 19:08:35",
		"updated_at": "2016-06-18 19:08:35",
		"pivot": {
			"recipient_id": 3,
			"sender_id": 1,
			"created_at": "2016-06-19 19:53:27",
			"updated_at": "2016-06-19 22:56:40",
			"status": 1
		}
	}]
},
{
	"id": 4,
	"name": "random_user",
	"created_at": "2016-06-19 19:55:25",
	"updated_at": "2016-06-19 19:55:25",
	"friends_i_am_sender": [],
	"friends_i_am_recipient": []
}]
```

\## License Friends is free software distributed under the terms of the MIT license.

[![Analytics](https://camo.githubusercontent.com/2af560b6656682cc5f89ea0a31ef7a20c89221c593b72cfe53109ac78859f9f9/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d37373733373135362d312f726561646d653f706978656c)](https://github.com/arubacao/friends)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

3611d ago

### Community

Maintainers

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

---

Top Contributors

[![hootlex](https://avatars.githubusercontent.com/u/6147968?v=4)](https://github.com/hootlex "hootlex (97 commits)")[![arubacao](https://avatars.githubusercontent.com/u/7462542?v=4)](https://github.com/arubacao "arubacao (92 commits)")[![stephane-monnot](https://avatars.githubusercontent.com/u/6066368?v=4)](https://github.com/stephane-monnot "stephane-monnot (8 commits)")[![irazasyed](https://avatars.githubusercontent.com/u/1915268?v=4)](https://github.com/irazasyed "irazasyed (1 commits)")[![nilportugues](https://avatars.githubusercontent.com/u/550948?v=4)](https://github.com/nilportugues "nilportugues (1 commits)")

---

Tags

laravellumeneloquentfriendsRelationshipsfriendshipsfriend-system

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[multicaret/laravel-acquaintances

This light package, with no dependencies, gives Eloquent models the ability to manage friendships (with groups), verifications, and interactions such as: Likes, favorites, votes, subscribe, follow, ..etc. And it includes advanced rating system.

851266.9k2](/packages/multicaret-laravel-acquaintances)[hootlex/laravel-friendships

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

705114.6k](/packages/hootlex-laravel-friendships)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[merodiro/friendships

This package gives users the ability to manage their friendships.

459.7k](/packages/merodiro-friendships)[demency/laravel-friendships

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

201.0k](/packages/demency-laravel-friendships)

PHPackages © 2026

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