kayw-geek/yii2-follow

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

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0

Type:yii2-extension

V1.0 2020-09-17 09:43 UTC

This package is auto-updated.

Last update: 2024-04-19 07:09:05 UTC


README

User follow unfollow system for Yii2.

FOSSA Status GitHub code size in bytes GitHub

Installing

$ composer require kayw-geek/yii2-follow

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

Traits

kaywGeek\Follow\FollowerTrait

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

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

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

Get followings:

$user->followings;

Get followers:

$user->followers;

Aggregations

// with query where
$user->followings()->where(['<',['follow_at'=>date('Y-m-d')]])->all();

// followers orderBy
$user->followers()->orderBy('follow_at desc');

License

FOSSA Status