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

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

temian/laravel-befriended
=========================

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

01PHP

Since Apr 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Temian1/laravel-social-befriend)[ Packagist](https://packagist.org/packages/temian/laravel-befriended)[ RSS](/packages/temian-laravel-befriended/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#laravel-befriended)

[![CI](https://github.com/renoki-co/befriended/workflows/CI/badge.svg?branch=master)](https://github.com/renoki-co/befriended/workflows/CI/badge.svg?branch=master)[![codecov](https://camo.githubusercontent.com/1021b6304e8be48062eaecac62a51872943920add621e8d852a5e07419934a61/68747470733a2f2f636f6465636f762e696f2f67682f72656e6f6b692d636f2f6265667269656e6465642f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/renoki-co/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)

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

🤝 Supporting
------------

[](#-supporting)

**If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with [Github Sponsors](https://github.com/sponsors/rennokki). 📦**

[![](https://camo.githubusercontent.com/7f483b7888f179176a014241040b590febc0836c633ee516304229a0581c3c7b/68747470733a2f2f6769746875622d636f6e74656e742e73332e66722d7061722e7363772e636c6f75642f7374617469632f32312e6a7067)](https://github-content.renoki.org/github-repo/21)

🚀 Installation
--------------

[](#-installation)

Install the package:

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

Publish the config:

```
$ php artisan vendor:publish --provider="Rennokki\Befriended\BefriendedServiceProvider" --tag="config"
```

Publish the migrations:

```
$ php artisan vendor:publish --provider="Rennokki\Befriended\BefriendedServiceProvider" --tag="migrations"
```

🙌 Usage
-------

[](#-usage)

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
```

Some users might want to remove followers from their list. The `Followable` trait comes with a `revokeFollower` method:

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

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

**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
```

Follow requests
---------------

[](#follow-requests)

This is similar to the way Instagram allows you to request follow of a private profile.

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 follower requests or request to follow a users:

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

$user->followRequests()->count(); // 1
$zuck->followerRequests()->count(); // 1
$user->follows($zuck); // false
$zuck->acceptFollowRequest($user); // true
$user->follows($zuck); // true
```

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;
    ...
}
```

You can then request or cancel the follow requests:

```
$user->followRequest($zuck);
$user->cancelFollowRequest($zuck);
```

The one being followed can accept or decline the requests:

```
$zuck->acceptFollowRequest($user);
$zuck->declineFollowRequest($user);
```

By default, if querying `followRequests()` and `followerRequests()` 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->followRequest($zuckPage);
$user->followRequests()->count(); // 0, because it does not have any requests from any User instance
$user->followerRequests(Page::class)->count(); // 1, because it has a follow request for Zuck's page.
```

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

🐛 Testing
---------

[](#-testing)

```
vendor/bin/phpunit
```

🤝 Contributing
--------------

[](#-contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

🔒 Security
----------

[](#--security)

If you discover any security related issues, please email  instead of using the issue tracker.

🎉 Credits
---------

[](#-credits)

- [Alex Renoki](https://github.com/rennokki)
- [All Contributors](../../contributors)

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

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/d5332b731e1d74292dd2514693df159822027cdea967e29ce79206d3e5d97d17?d=identicon)[Kikismedia](/maintainers/Kikismedia)

---

Top Contributors

[![Temian1](https://avatars.githubusercontent.com/u/39234980?v=4)](https://github.com/Temian1 "Temian1 (5 commits)")

### Embed Badge

![Health badge](/badges/temian-laravel-befriended/health.svg)

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

###  Alternatives

[bolt/forms

📦 This Bolt extension can be used to handle forms in your Bolt project.

2223.8k1](/packages/bolt-forms)[webbycrown/blog-for-bagisto

Blog for Bagisto

257.0k](/packages/webbycrown-blog-for-bagisto)

PHPackages © 2026

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