Skip to content

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

License

Notifications You must be signed in to change notification settings

kayw-geek/yii2-follow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 Follow

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages