https://github.com/kayw-geek/yii2-follow
🤳🏻This package helps you to add user based follow system to your model.
https://github.com/kayw-geek/yii2-follow
favorite follow followers like subscribe yii2-extension
Last synced: 2 months ago
JSON representation
🤳🏻This package helps you to add user based follow system to your model.
- Host: GitHub
- URL: https://github.com/kayw-geek/yii2-follow
- Owner: kayw-geek
- License: mit
- Created: 2020-09-17T06:32:57.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-18T23:34:17.000Z (almost 5 years ago)
- Last Synced: 2025-02-16T18:18:35.837Z (5 months ago)
- Topics: favorite, follow, followers, like, subscribe, yii2-extension
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yii2 Follow
User follow unfollow system for Yii2.
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fkayw-geek%2Fyii2-follow?ref=badge_shield)  
## 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
```php
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
```php
$user1 = User::findOne(1);
$user2 = User::findOne(2);$user1->follow($user2);
$user1->unfollow($user2);
$user1->checkFollowed($user2);
$user1->followedCount();
$user1->followerCount();
```#### Get followings:
```php
$user->followings;
```#### Get followers:
```php
$user->followers;
```### Aggregations
```php
// with query where
$user->followings()->where(['<',['follow_at'=>date('Y-m-d')]])->all();// followers orderBy
$user->followers()->orderBy('follow_at desc');
```# License
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fkayw-geek%2Fyii2-follow?ref=badge_large)