PHPackages                             developer-savyour/befriended - 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. developer-savyour/befriended

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

developer-savyour/befriended
============================

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

1.4.1(6y ago)0193MITPHP

Since Jul 17Pushed 6y agoCompare

[ Source](https://github.com/developers-savyour/befriended)[ Packagist](https://packagist.org/packages/developer-savyour/befriended)[ Docs](https://github.com/rennokki/befriended)[ RSS](/packages/developer-savyour-befriended/feed)WikiDiscussions master Synced yesterday

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

[![Build Status](https://camo.githubusercontent.com/65f685d471a6e55e619b434f70cfb9c5dbabc70f645b9dfc6b975248d556b03b/68747470733a2f2f7472617669732d63692e6f72672f72656e6e6f6b6b692f6265667269656e6465642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rennokki/befriended)[![codecov](https://camo.githubusercontent.com/3f91b50e1f6d536679fb94eae8b6c9862122f7bb63378b21212081aabaabb125/68747470733a2f2f636f6465636f762e696f2f67682f72656e6e6f6b6b692f6265667269656e6465642f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/rennokki/befriended/branch/master)[![StyleCI](https://camo.githubusercontent.com/717c9f98cbe72250e06d5cb381cc8f6334794aa0ba19134821689eb7f382e47f/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134313139343535312f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/141194551)[![Latest Stable Version](https://camo.githubusercontent.com/2ebb1e09f3287472bf8818d873b45b78e5e376b9aa9460d1c16a36954750cd2c/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6265667269656e6465642f762f737461626c65)](https://packagist.org/packages/rennokki/befriended)[![Total Downloads](https://camo.githubusercontent.com/9f6581cd257e666ba1df35bec567b8f8d0cddd934f7dec4d77fadc7329defcf8/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6265667269656e6465642f646f776e6c6f616473)](https://packagist.org/packages/rennokki/befriended)[![Monthly Downloads](https://camo.githubusercontent.com/4ee89110082539c94d13a32a80bd9230e351626f12f02b5170633e549c43985e/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6265667269656e6465642f642f6d6f6e74686c79)](https://packagist.org/packages/rennokki/befriended)[![License](https://camo.githubusercontent.com/f09fd4f54e616037303f800add5aed47bfce69637a5303be84eff3ac157140b1/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6265667269656e6465642f6c6963656e7365)](https://packagist.org/packages/rennokki/befriended)

[![PayPal](https://camo.githubusercontent.com/e3d021da65162fda975bd58ef4a4d80bdd03d6e94aa1b321d179e6b4c1aff357/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50617950616c2d646f6e6174652d626c75652e737667)](https://paypal.me/rennokki)

Laravel Befriended
==================

[](#laravel-befriended)

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models. Laravel Befriended comes with scopes that manage filtering content that gives you easy control better what your user can see and cannot see.

Switching from 1.1.x to 1.2.x
=============================

[](#switching-from-11x-to-12x)

The main difference is that the traits that are responsible for filtering content got a better eloquent capability.

Make sure you replace the following traits:

- `Rennokki\Befriended\Scopes\CanFilterFollowingModels`
- `Rennokki\Befriended\Scopes\CanFilterUnfollowedModels`
- `Rennokki\Befriended\Scopes\CanFilterBlockedModels`
- `Rennokki\Befriended\Scopes\CanFilterUnlikedModels`

with the following ones that are paired by the action they filter:

- `Rennokki\Befriended\Scopes\FollowFilterable`
- `Rennokki\Befriended\Scopes\BlockFilterable`
- `Rennokki\Befriended\Scopes\LikeFilterable`

Installation
============

[](#installation)

Install the package:

```
$ composer require rennokki/befriended
```

If your Laravel version does not support package discovery, add this line in the `providers` array in your `config/app.php` file:

```
Rennokki\Befriended\BefriendedServiceProvider::class,
```

Publish the config file &amp; migration files:

```
$ php artisan vendor:publish
```

Migrate the database:

```
$ php artisan migrate
```

Example
=======

[](#example)

The power of example is better here. This package allows you simply to assign followers, blockings or likes without too much effort. What makes the package powerful is that you can filter queries using scopes out-of-the-box.

```
$alice = User::where('name', 'Alice')->first();
$bob = User::where('name', 'Bob')->first();
$tim = User::where('name', 'Tim')->first();

$alice->follow($bob);

$alice->following()->count(); // 1
$bob->followers()->count(); // 1

User::followedBy($alice)->get(); // Just Bob shows up
User::unfollowedBy($alice)->get(); // Tim shows up
```

Following
=========

[](#following)

To follow other models, your model should use the `CanFollow` trait and `Follower` contract.

```
use Rennokki\Befriended\Traits\CanFollow;
use Rennokki\Befriended\Contracts\Follower;

class User extends Model implements Follower {
    use CanFollow;
    ...
}
```

The other models that can be followed should use `CanBeFollowed` trait and `Followable` contract.

```
use Rennokki\Befriended\Traits\CanBeFollowed;
use Rennokki\Befriended\Contracts\Followable;

class User extends Model implements Followable {
    use CanBeFollowed;
    ...
}
```

If your model can both follow &amp; be followed, you can use `Follow` trait and `Following` contract.

```
use Rennokki\Befriended\Traits\Follow;
use Rennokki\Befriended\Contracts\Following;

class User extends Model implements Following {
    use Follow;
    ...
}
```

Let's suppose we have an `User` model which can follow and be followed. Within it, we can now check for followers or follow new users:

```
$zuck = User::where('name', 'Mark Zuckerberg')->first();
$user->follow($zuck);

$user->following()->count(); // 1
$zuck->followers()->count(); // 1
```

Now, let's suppose we have a `Page` model, than can only be followed:

```
use Rennokki\Befriended\Traits\CanBeFollowed;
use Rennokki\Befriended\Contracts\Followable;

class Page extends Model implements Followable {
    use CanBeFollowed;
    ...
}
```

By default, if querying `following()` and `followers()` from the `User` instance, the relationships will return only `User` instances. If you plan to retrieve other instances, such as `Page`, you can pass the model name or model class as an argument to the relationships:

```
$zuckPage = Page::where('username', 'zuck')->first();

$user->follow($zuckPage);
$user->following()->count(); // 0, because it doesn't follow any User instance
$user->following(Page::class)->count(); // 1, because it follows only Zuck's page.
```

On-demand, you can check if your model follows some other model:

```
$user->isFollowing($friend);
$user->follows($friend); // alias
```

**Note: Following, unfollowing or checking if following models that do not correctly implement `CanBeFollowed` and `Followable` will always return `false`.**

### Filtering followed/unfollowed models

[](#filtering-followedunfollowed-models)

To filter followed or unfollowed models (which can be any other model) on query, your model which you will query should use the `Rennokki\Befriended\Scopes\FollowFilterable` trait.

If your `User` model can only like other `Page` models, your `Page` model should use the trait mentioned.

```
$bob = User::where('username', 'john')->first();
$alice = User::where('username', 'alice')->first();

User::followedBy($bob)->get(); // You will get no results.
User::unfollowedBy($bob)->get(); // You will get Alice.

$bob->follow($alice);
User::followedBy($bob)->get(); // Only Alice pops up.
```

Blocking
========

[](#blocking)

Most of the functions are working like the follow feature, but this is helpful when your models would like to block other models.

Use `CanBlock` trait and `Blocker` contract to allow the model to block other models.

```
use Rennokki\Befriended\Traits\CanBlock;
use Rennokki\Befriended\Contracts\Blocker;

class User extends Model implements Blocker {
    use CanBlock;
    ...
}
```

Adding `CanBeBlocked` trait and `Blockable` contract sets the model able to be blocked.

```
use Rennokki\Befriended\Traits\CanBeBlocked;
use Rennokki\Befriended\Contracts\Blockable;

class User extends Model implements Blockable {
    use CanBeBlocked;
    ...
}
```

For both, you should be using `Block` trait &amp; `Blocking` contract:

```
use Rennokki\Befriended\Traits\Block;
use Rennokki\Befriended\Contracts\Blocking;

class User extends Model implements Blocking {
    use Block;
    ...
}
```

Most of the methods are the same:

```
$user->block($user);
$user->block($page);
$user->unblock($user);

$user->blocking(); // Users that this user blocks.
$user->blocking(Page::class); // Pages that this user blocks.
$user->blockers(); // Users that block this user.
$user->blockers(Page::class); // Pages that block this user.

$user->isBlocking($page);
$user->blocks($page); // alias to isBlocking
```

### Filtering blocked models

[](#filtering-blocked-models)

Blocking scopes provided takes away from the query the models that are blocked. Useful to stop showing content when your models blocks other models. Make sure that the model that will be queried uses the `Rennokki\Befriended\Scopes\BlockFilterable` trait.

```
$bob = User::where('username', 'john')->first();
$alice = User::where('username', 'alice')->first();

User::withoutBlockingsOf($bob)->get(); // You will get Alice and Bob as results.

$bob->block($alice);
User::withoutBlockingsOf($bob)->get(); // You will get only Bob as result.
```

Liking
======

[](#liking)

Apply `CanLike` trait and `Liker` contract for models that can like:

```
use Rennokki\Befriended\Traits\CanLike;
use Rennokki\Befriended\Contracts\Liker;

class User extends Model implements Liker {
    use CanLike;
    ...
}
```

`CanBeLiked` and `Likeable` trait can be used for models that can be liked:

```
use Rennokki\Befriended\Traits\CanBeLiked;
use Rennokki\Befriended\Contracts\Likeable;

class Page extends Model implements Likeable {
    use CanBeLiked;
    ...
}
```

Planning to use both, use the `Like` trait and `Liking` contact:

```
use Rennokki\Befriended\Traits\Like;
use Rennokki\Befriended\Contracts\Liking;

class User extends Model implements Liking {
    use Like;
    ...
}
```

As you have already got started with, these are the methods:

```
$user->like($user);
$user->like($page);
$user->unlike($page);

$user->liking(); // Users that this user likes.
$user->liking(Page::class); // Pages that this user likes.
$user->likers(); // Users that like this user.
$user->likers(Page::class); // Pages that like this user.

$user->isLiking($page);
$user->likes($page); // alias to isLiking
```

### Filtering liked content

[](#filtering-liked-content)

Filtering liked content can make showing content easier. For example, showing in the news feed posts that weren't liked by an user can be helpful. The model you're querying from must use the `Rennokki\Befriended\Scopes\LikeFilterable` trait.

Let's suppose there are 10 pages in the database.

```
$bob = User::where('username', 'john')->first();
$page = Page::find(1);

Page::notLikedBy($bob)->get(); // You will get 10 results.

$bob->like($page);
Page::notLikedBy($bob)->get(); // You will get only 9 results.
Page::likedBy($bob)->get(); // You will get one result, the $page
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 79.5% 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

Every ~23 days

Recently: every ~88 days

Total

19

Last Release

2440d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/786b199a167521eaad6356220d2278a20e44d89777b5606fe445c840f11111cb?d=identicon)[developers-savyour](/maintainers/developers-savyour)

---

Top Contributors

[![rennokki](https://avatars.githubusercontent.com/u/21983456?v=4)](https://github.com/rennokki "rennokki (35 commits)")[![shahrukhan](https://avatars.githubusercontent.com/u/20871899?v=4)](https://github.com/shahrukhan "shahrukhan (3 commits)")[![rez1dent3](https://avatars.githubusercontent.com/u/5111255?v=4)](https://github.com/rez1dent3 "rez1dent3 (2 commits)")[![Clayboy](https://avatars.githubusercontent.com/u/1386860?v=4)](https://github.com/Clayboy "Clayboy (1 commits)")[![pkboom](https://avatars.githubusercontent.com/u/13960169?v=4)](https://github.com/pkboom "pkboom (1 commits)")[![josezenem](https://avatars.githubusercontent.com/u/377520?v=4)](https://github.com/josezenem "josezenem (1 commits)")[![lukadriel7](https://avatars.githubusercontent.com/u/10757342?v=4)](https://github.com/lukadriel7 "lukadriel7 (1 commits)")

---

Tags

laravellinkmodeleloquentmediaConnectionsocialfriendsblockconnectionsblockingFollowersfriendblocker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/developer-savyour-befriended/health.svg)

```
[![Health](https://phpackages.com/badges/developer-savyour-befriended/health.svg)](https://phpackages.com/packages/developer-savyour-befriended)
```

###  Alternatives

[rennokki/befriended

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

76292.2k1](/packages/rennokki-befriended)[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)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)

PHPackages © 2026

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