PHPackages                             presetshare/yii2-entity-like - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. presetshare/yii2-entity-like

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

presetshare/yii2-entity-like
============================

User-like features for Yii2 Applications

055PHP

Since Feb 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/PresetShare/yii2-entity-like)[ Packagist](https://packagist.org/packages/presetshare/yii2-entity-like)[ RSS](/packages/presetshare-yii2-entity-like/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-entity-like
================

[](#yii2-entity-like)

[![Total Downloads](https://camo.githubusercontent.com/d9d70d73a132a94212ac3eab7d6e227e69220e0e7a200983b9f850e4f27da29e/68747470733a2f2f706f7365722e707567782e6f72672f70726573657473686172652f796969322d656e746974792d6c696b652f646f776e6c6f6164732e737667)](https://packagist.org/packages/presetshare/yii2-entity-like)[![License](https://camo.githubusercontent.com/5826ba3005bfc1b4aee86659f071645426a3f93a42af723403f89683b6c0d70b/68747470733a2f2f706f7365722e707567782e6f72672f70726573657473686172652f796969322d656e746974792d6c696b652f6c6963656e73652e737667)](https://packagist.org/packages/presetshare/yii2-entity-like)

❤️ User-like features for Yii2 Applications.

[![How yii2-entity-like works](https://raw.githubusercontent.com/presetshare/yii2-entity-like/master/docs/showcase.gif)](https://raw.githubusercontent.com/presetshare/yii2-entity-like/master/docs/showcase.gif)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer require --prefer-dist presetshare/yii2-entity-like "@dev"

```

or add

```
"presetshare/yii2-entity-like": "@dev"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Migrations

```
php yii migrate/up --migrationPath=@vendor/presetshare/yii2-entity-like/migrations
```

Module config

```
'modules' => [
    'entityLike' => [
        'class' => \presetshare\yii2\likes\Module::class,
        'entities' => [
            \app\models\Post::class
        ],
    ],
],
```

Model behavior

```
class Post extends \yii\db\ActiveRecord
{
    ...
    public function behaviors()
    {
        return [
            [
                'class' => \presetshare\yii2\likes\behaviors\LikeableEntityBehavior::class,
                'authorAttribute' => 'user_id'
            ]
        ];
    }
    ...
}
```

Query trait

```
class PostQuery extends \yii\db\ActiveQuery
{
    use \presetshare\yii2\likes\traits\EntityLikeQueries;
    ...
}
```

Queries

```
$dataProvider = new ActiveDataProvider([
    'query' => Post::find()
        ->withLikesCount()
        ->withHasMyLike()
        //->onlyLikedByMe()

        ->orderBy(['likes_count' => SORT_DESC, 'post.id' => SORT_DESC]),
    'pagination' => [
        'pageSize' => 15,
        'defaultPageSize' => 15,
    ],
]);

$posts = $dataProvider->getModels();

$post = Post::find()->where(['post.id' => $id])->withLikesCount()->withHasMyLike()->one();

$likesCount = $post->likes_count;
$hasMyLike = $post->has_my_like;
```

Widget

```

```

Events

```
