PHPackages                             birdie/laravel-follow - 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. birdie/laravel-follow

ActiveLibrary

birdie/laravel-follow
=====================

Laravel 5 User Based System

1.1.14(6y ago)014MITPHPPHP &gt;=7.0

Since Nov 11Pushed 6y agoCompare

[ Source](https://github.com/ACmagic/laravel-follow)[ Packagist](https://packagist.org/packages/birdie/laravel-follow)[ RSS](/packages/birdie-laravel-follow/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (3)Versions (18)Used By (0)

Laravel 5 Follow System
=======================

[](#laravel-5-follow-system)

❤️ This package helps you to add user based follow system to your model.

[![Build Status](https://camo.githubusercontent.com/c601ee737863ccce64adbce39527d1dd65f967c386b20a5c07f8ae7b3419f2f1/68747470733a2f2f7472617669732d63692e6f72672f6f766572747275652f6c61726176656c2d666f6c6c6f772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/overtrue/laravel-follow)[![Latest Stable Version](https://camo.githubusercontent.com/71cc1eca2202f6bf9ca9fb4eebd1fb050d0b601e7a2b3946661b741fcba6f249/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d666f6c6c6f772f762f737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-follow)[![Latest Unstable Version](https://camo.githubusercontent.com/e38875130ff4d49c125eb299d634f0707d73779c7c092c150afeb229adf45e4d/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d666f6c6c6f772f762f756e737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-follow)[![Build Status](https://camo.githubusercontent.com/70012871b1f3519fcd34135f898c3c690cf9212117f3681076f79a4ac410ff84/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f766572747275652f6c61726176656c2d666f6c6c6f772f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/overtrue/laravel-follow/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/692c5bfcace74033c36ec7dbe556a2414824f74b055be2f34e2299f7ce1a643a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f766572747275652f6c61726176656c2d666f6c6c6f772f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/overtrue/laravel-follow/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/6d7123892d02f29589f8f6701d311e5b77c66041b0a60bef97f11b02185929ae/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f766572747275652f6c61726176656c2d666f6c6c6f772f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/overtrue/laravel-follow/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/31d8c72d9d58e17500daa8919681b4291aacd7a438ff44ef311fb2aa73dad722/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d666f6c6c6f772f646f776e6c6f616473)](https://packagist.org/packages/overtrue/laravel-follow)[![License](https://camo.githubusercontent.com/66bd0ede32b58beacb2660d3542e3c6bfe9944c7c278b2962e0b7483d3b94a83/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d666f6c6c6f772f6c6963656e7365)](https://packagist.org/packages/overtrue/laravel-follow)

Features
--------

[](#features)

- Support actions:
    - Follow
    - Like
    - Bookmark
    - Subscribe
    - Favorite
    - Vote (Upvote &amp; Downvote)

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

[](#installation)

### Required

[](#required)

- PHP 7.0 +
- Laravel 5.5 +

You can install the package using composer

```
$ composer require overtrue/laravel-follow -vvv
```

Then add the service provider to `config/app.php`

```
Overtrue\LaravelFollow\FollowServiceProvider::class
```

Publish the migrations file:

```
$ php artisan vendor:publish --provider="Overtrue\LaravelFollow\FollowServiceProvider" --tag="migrations"
```

As optional if you want to modify the default configuration, you can publish the configuration file:

```
$ php artisan vendor:publish --provider="Overtrue\LaravelFollow\FollowServiceProvider" --tag="config"
```

And create tables:

```
$ php artisan migrate
```

Finally, add feature trait into User model:

```
use Overtrue\LaravelFollow\Traits\CanFollow;
use Overtrue\LaravelFollow\Traits\CanBeFollowed;

class User extends Model
{
    use CanFollow, CanBeFollowed;
}
```

Usage
-----

[](#usage)

Add `CanXXX` Traits to User model.

```
use Overtrue\LaravelFollow\Traits\CanFollow;
use Overtrue\LaravelFollow\Traits\CanLike;
use Overtrue\LaravelFollow\Traits\CanFavorite;
use Overtrue\LaravelFollow\Traits\CanSubscribe;
use Overtrue\LaravelFollow\Traits\CanVote;
use Overtrue\LaravelFollow\Traits\CanBookmark;

class User extends Model
{
    use CanFollow, CanBookmark, CanLike, CanFavorite, CanSubscribe, CanVote;
}
```

Add `CanBeXXX` Trait to target model, such as 'Post' or 'Music' ...:

```
use Overtrue\LaravelFollow\Traits\CanBeLiked;
use Overtrue\LaravelFollow\Traits\CanBeFavorited;
use Overtrue\LaravelFollow\Traits\CanBeVoted;
use Overtrue\LaravelFollow\Traits\CanBeBookmarked;

class Post extends Model
{
    use CanBeLiked, CanBeFavorited, CanBeVoted, CanBeBookmarked;
}
```

All available APIs are listed below.

### Follow

[](#follow)

#### `\Overtrue\LaravelFollow\Traits\CanFollow`

[](#overtruelaravelfollowtraitscanfollow)

```
$user->follow($targets)
$user->unfollow($targets)
$user->toggleFollow($targets)
$user->followings()->get() // App\User:class
$user->followings(App\Post::class)->get()
$user->areFollowingEachOther($anotherUser);
$user->isFollowing($target)
```

#### `\Overtrue\LaravelFollow\Traits\CanBeFollowed`

[](#overtruelaravelfollowtraitscanbefollowed)

```
$object->followers()->get()
$object->isFollowedBy($user)
```

### Bookmark

[](#bookmark)

#### `\Overtrue\LaravelFollow\Traits\CanBookmark`

[](#overtruelaravelfollowtraitscanbookmark)

```
$user->bookmark($targets)
$user->unbookmark($targets)
$user->toggleBookmark($targets)
$user->hasBookmarked($target)
$user->bookmarks()->get() // App\User:class
$user->bookmarks(App\Post::class)->get()
```

#### `\Overtrue\LaravelFollow\Traits\CanBeBookmarked`

[](#overtruelaravelfollowtraitscanbebookmarked)

```
$object->bookmarkers()->get() // or $object->bookmarkers
$object->isBookmarkedBy($user)
```

### Like

[](#like)

#### `\Overtrue\LaravelFollow\Traits\CanLike`

[](#overtruelaravelfollowtraitscanlike)

```
$user->like($targets)
$user->unlike($targets)
$user->toggleLike($targets)
$user->hasLiked($target)
$user->likes()->get() // default object: App\User:class
$user->likes(App\Post::class)->get()
```

#### `\Overtrue\LaravelFollow\Traits\CanBeLiked`

[](#overtruelaravelfollowtraitscanbeliked)

```
$object->likers()->get() // or $object->likers
$object->fans()->get() // or $object->fans
$object->isLikedBy($user)
```

### Favorite

[](#favorite)

#### `\Overtrue\LaravelFollow\Traits\CanFavorite`

[](#overtruelaravelfollowtraitscanfavorite)

```
$user->favorite($targets)
$user->unfavorite($targets)
$user->toggleFavorite($targets)
$user->hasFavorited($target)
$user->favorites()->get() // App\User:class
$user->favorites(App\Post::class)->get()
```

#### `\Overtrue\LaravelFollow\Traits\CanBeFavorited`

[](#overtruelaravelfollowtraitscanbefavorited)

```
$object->favoriters()->get() // or $object->favoriters
$object->isFavoritedBy($user)
```

### Subscribe

[](#subscribe)

#### `\Overtrue\LaravelFollow\Traits\CanSubscribe`

[](#overtruelaravelfollowtraitscansubscribe)

```
$user->subscribe($targets)
$user->unsubscribe($targets)
$user->toggleSubscribe($targets)
$user->hasSubscribed($target)
$user->subscriptions()->get() // default object: App\User:class
$user->subscriptions(App\Post::class)->get()
```

#### `Overtrue\LaravelFollow\Traits\CanBeSubscribed`

[](#overtruelaravelfollowtraitscanbesubscribed)

```
$object->subscribers() // or $object->subscribers
$object->isSubscribedBy($user)
```

### Vote

[](#vote)

#### `\Overtrue\LaravelFollow\Traits\CanVote`

[](#overtruelaravelfollowtraitscanvote)

```
$user->vote($target) // Vote with 'upvote' for default
$user->upvote($target)
$user->downvote($target)
$user->cancelVote($target)
$user->hasUpvoted($target)
$user->hasDownvoted($target)
$user->votes(App\Post::class)->get()
$user->upvotes(App\Post::class)->get()
$user->downvotes(App\Post::class)->get()
```

#### `\Overtrue\LaravelFollow\Traits\CanBeVoted`

[](#overtruelaravelfollowtraitscanbevoted)

```
$object->voters()->get()
$object->upvoters()->get()
$object->downvoters()->get()
$object->isVotedBy($user)
$object->isUpvotedBy($user)
$object->isDownvotedBy($user)
```

### Parameters

[](#parameters)

All of the above mentioned methods of creating relationships, such as 'follow', 'like', 'unfollow', 'unlike', their syntax is as follows:

```
follow(array|int|\Illuminate\Database\Eloquent\Model $targets, $class = __CLASS__)
```

So you can call them like this:

```
// Id / Id array
$user->follow(1); // targets: 1, $class = App\User
$user->follow(1, App\Post::class); // targets: 1, $class = App\Post
$user->follow([1, 2, 3]); // targets: [1, 2, 3], $class = App\User

// Model
$post = App\Post::find(7);
$user->follow($post); // targets: $post->id, $class = App\Post

// Model array
$posts = App\Post::popular()->get();
$user->follow($posts); // targets: [1, 2, ...], $class = App\Post
```

### Query relations

[](#query-relations)

```
$followers = $user->followers
$followers = $user->followers()->where('id', '>', 10)->get()
$followers = $user->followers()->orderByDesc('id')->get()
```

The other is the same usage.

### Working with model.

[](#working-with-model)

```
use Overtrue\LaravelFollow\FollowRelation;

// get most popular object

// all types
$relations = FollowRelation::popular()->get();

// followable_type = App\Post
$relations = FollowRelation::popular(App\Post::class)->get();

// followable_type = App\User
$relations = FollowRelation::popular('user')->get();

// followable_type = App\Post
$relations = FollowRelation::popular('post')->get();

// Pagination
$relations = FollowRelation::popular(App\Post::class)->paginate(15);
```

### Events

[](#events)

- `Overtrue\LaravelFollow\RelationAttaching`
- `Overtrue\LaravelFollow\RelationAttached`
- `Overtrue\LaravelFollow\RelationDetaching`
- `Overtrue\LaravelFollow\RelationDetached`
- `Overtrue\LaravelFollow\RelationToggling`
- `Overtrue\LaravelFollow\RelationToggled`

```
Event::listen(\Overtrue\LaravelFollow\RelationAttached::class, function($event) {
    // $event->causer;
    // $event->getTargetsCollection();
    // $event->getRelationType();
});
```

About toggled event.
====================

[](#about-toggled-event)

There has a extra properties for `Overtrue\LaravelFollow\RelationToggled` event.

```
$event->results; // ['attached' => [1, 2, 3], 'detached' => [5, 6]]
$event->attached; // [1, 2, 3]
$event->detached; // [5, 6]
```

PHP 扩展包开发
---------

[](#php-扩展包开发)

> 想知道如何从零开始构建 PHP 扩展包？
>
> 请关注我的实战课程，我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 74.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 ~64 days

Recently: every ~73 days

Total

17

Last Release

2444d ago

PHP version history (3 changes)1.0PHP &gt;=5.4

1.1.0PHP &gt;=5.5.9

1.1.8PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/87ab97dd48feaaebce0edf9aa3b1ac81843b130b97677ac13955ec2a735c421b?d=identicon)[lancer](/maintainers/lancer)

---

Top Contributors

[![overtrue](https://avatars.githubusercontent.com/u/1472352?v=4)](https://github.com/overtrue "overtrue (102 commits)")[![Mombuyish](https://avatars.githubusercontent.com/u/8007787?v=4)](https://github.com/Mombuyish "Mombuyish (6 commits)")[![vincentvankekerix](https://avatars.githubusercontent.com/u/32239111?v=4)](https://github.com/vincentvankekerix "vincentvankekerix (4 commits)")[![p3yman](https://avatars.githubusercontent.com/u/2673262?v=4)](https://github.com/p3yman "p3yman (4 commits)")[![kevincobain2000](https://avatars.githubusercontent.com/u/629055?v=4)](https://github.com/kevincobain2000 "kevincobain2000 (3 commits)")[![jcc](https://avatars.githubusercontent.com/u/12684082?v=4)](https://github.com/jcc "jcc (3 commits)")[![ACmagic](https://avatars.githubusercontent.com/u/6644559?v=4)](https://github.com/ACmagic "ACmagic (3 commits)")[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")[![thisliu](https://avatars.githubusercontent.com/u/29086766?v=4)](https://github.com/thisliu "thisliu (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![summerblue](https://avatars.githubusercontent.com/u/324764?v=4)](https://github.com/summerblue "summerblue (1 commits)")[![entimm](https://avatars.githubusercontent.com/u/1958077?v=4)](https://github.com/entimm "entimm (1 commits)")[![Frankisgek](https://avatars.githubusercontent.com/u/487218?v=4)](https://github.com/Frankisgek "Frankisgek (1 commits)")[![AdrianHL](https://avatars.githubusercontent.com/u/16022257?v=4)](https://github.com/AdrianHL "AdrianHL (1 commits)")[![EazyServer](https://avatars.githubusercontent.com/u/19202935?v=4)](https://github.com/EazyServer "EazyServer (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/birdie-laravel-follow/health.svg)

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

PHPackages © 2026

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