PHP code example of kayw-geek / yii2-follow

1. Go to this page and download the library: Download kayw-geek/yii2-follow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kayw-geek / yii2-follow example snippets


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

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

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

$user->followings;

$user->followers;

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

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