PHPackages                             kayw-geek/yii2-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. kayw-geek/yii2-follow

ActiveYii2-extension

kayw-geek/yii2-follow
=====================

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

V1.0(5y ago)101MITPHP

Since Sep 17Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kayw-geek/yii2-follow)[ Packagist](https://packagist.org/packages/kayw-geek/yii2-follow)[ RSS](/packages/kayw-geek-yii2-follow/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Yii2 Follow
===========

[](#yii2-follow)

User follow unfollow system for Yii2.

[![FOSSA Status](https://camo.githubusercontent.com/2dbf4c8467f40457ff60ebdebf0a3228b7decc6a15c38ee884448e4406db3d5f/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466b6179772d6765656b253246796969322d666f6c6c6f772e7376673f747970653d736869656c64)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkayw-geek%2Fyii2-follow?ref=badge_shield) [![GitHub code size in bytes](https://camo.githubusercontent.com/91d3d7247b4f94cebbe0a917997d1cc46e66c18ffbc77a0277690e2619dd1f56/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6b6179772d6765656b2f796969322d666f6c6c6f77)](https://camo.githubusercontent.com/91d3d7247b4f94cebbe0a917997d1cc46e66c18ffbc77a0277690e2619dd1f56/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6b6179772d6765656b2f796969322d666f6c6c6f77) [![GitHub](https://camo.githubusercontent.com/50e9ea3e403b49e5d3a75ad3d883e49228de7a1ec5666cf751075cf7389d17a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b6179772d6765656b2f796969322d666f6c6c6f77)](https://camo.githubusercontent.com/50e9ea3e403b49e5d3a75ad3d883e49228de7a1ec5666cf751075cf7389d17a5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b6179772d6765656b2f796969322d666f6c6c6f77)

Installing
----------

[](#installing)

```
$ composer require kayw-geek/yii2-follow

```

### Migrations

[](#migrations)

This step is also optional, if you want to custom the pivot table, you can publish the migration files:

```
$ yii migrate/up --migrationPath=@vendor/kayw-geek/yii2-follow/migrations

```

Usage
-----

[](#usage)

### Traits

[](#traits)

#### kaywGeek\\Follow\\FollowerTrait

[](#kaywgeekfollowfollowertrait)

```
use kaywGeek\follow\FollowerTrait;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;

class User extends ActiveRecord implements IdentityInterface
{

    use FollowerTrait;

}
```

### API

[](#api)

```
$user1 = User::findOne(1);
$user2 = User::findOne(2);

$user1->follow($user2);
$user1->unfollow($user2);
$user1->checkFollowed($user2);
$user1->followedCount();
$user1->followerCount();
```

#### Get followings:

[](#get-followings)

```
$user->followings;
```

#### Get followers:

[](#get-followers)

```
$user->followers;
```

### Aggregations

[](#aggregations)

```
// with query where
$user->followings()->where(['
