PHPackages                             toneflix-code/social-interactions - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. toneflix-code/social-interactions

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

toneflix-code/social-interactions
=================================

A Laravel package to add social interactions like likes, reactions, votes, saving/bookmarks e.t.c to your models.

1.1.1(10mo ago)041[5 PRs](https://github.com/toneflix/laravel-social-interactions/pulls)MITPHPPHP ^8.2|^8.3CI passing

Since Jul 2Pushed 2mo agoCompare

[ Source](https://github.com/toneflix/laravel-social-interactions)[ Packagist](https://packagist.org/packages/toneflix-code/social-interactions)[ Docs](https://github.com/toneflix/laravel-social-interactions)[ RSS](/packages/toneflix-code-social-interactions/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (8)Versions (18)Used By (0)

Laravel Social Interactions (Save, Votes, Like, Dislike, React)
===============================================================

[](#laravel-social-interactions-save-votes-like-dislike-react)

[![Test & Lint](https://github.com/toneflix/laravel-social-interactions/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/toneflix/laravel-social-interactions/actions/workflows/run-tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/8d64135aabe47bd6105a8f27a24b9619c03cdbc7e84f37abda90257b4a475fc1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6e65666c69782d636f64652f736f6369616c2d696e746572616374696f6e732e7376673f7374796c653d666c61742d737175617265266c6162656c3d4c61746573742b537461626c652b56657273696f6e)](https://packagist.org/packages/toneflix-code/social-interactions) [![Total Downloads](https://camo.githubusercontent.com/01b75d2cce5668c0b6993e0d42601fed3e824dc69d10c676541dce58b6fb7a1a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f6e65666c69782d636f64652f736f6369616c2d696e746572616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/toneflix-code/social-interactions) [![Latest Unstable Version](https://camo.githubusercontent.com/d40d35795b13278440bdfbcb34dcda9b6be4fdde320c9604ded19d18c7f8e741/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6e65666c69782d636f64652f736f6369616c2d696e746572616374696f6e732e7376673f696e636c7564655f70726572656c6561736573267374796c653d666c61742d737175617265266c6162656c3d4c61746573742b556e737461626c652b56657273696f6e)](https://packagist.org/packages/toneflix-code/social-interactions) [![License](https://camo.githubusercontent.com/daf2ca8af62550b4fb9d632d8e4a921ecfe5583e6a26c43da53b6eeacf1be5e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f6e65666c69782f6c61726176656c2d736f6369616c2d696e746572616374696f6e73)](https://packagist.org/packages/toneflix-code/social-interactions) [![PHP Version Require](https://camo.githubusercontent.com/a0a06b6cca17cda44a5c0981fad5a3f845a9ca2888eb17e9d5f1b920777cd009/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f746f6e65666c69782d636f64652f736f6369616c2d696e746572616374696f6e732f706870)](https://packagist.org/packages/toneflix-code/social-interactions)[![codecov](https://camo.githubusercontent.com/eb75cadb0d536d5616f1467155923be629b35aa89a275419d0a51008d5bef683/68747470733a2f2f636f6465636f762e696f2f67682f746f6e65666c69782f6c61726176656c2d736f6369616c2d696e746572616374696f6e732f67726170682f62616467652e7376673f746f6b656e3d574a6679436e6d635a53)](https://codecov.io/gh/toneflix/laravel-social-interactions)

Laravel Social Interactions adds to your project the ability to create social interactions like **saves, votes, likes, dislikes, reactions, Etc.** with your models.

Contents
--------

[](#contents)

1. [**Use Cases**](#use-cases)
2. [**Installation**](#installation)
3. [**Package Discovery**](#package-discovery)
4. [**Configuration**](#configuration)
5. [**Usage**](#usage)
    - [Likes](#likes)
    - [Dislikes](#dislikes)
    - [Reactions](#reactions)
    - [Votes](#votes)
    - [Saving](#saving)
    - [Accessing the interaction relationship](#accessing-the-interaction-relationship)
    - [Accessing the interactor relationship](#accessing-the-interactor-relationship)
    - [Accessing the interaction relationship for the interacting model](#accessing-the-interaction-relationship-for-the-interacting-model)
    - [Get Model Interaction for a specific Interactor](#get-model-interaction-for-a-specific-interactor)
    - [Get Interaction Data](#get-interaction-data)
    - [Accessing saved items relationship](#accessing-saved-items-relationship)
    - [Accessing saved items relationship for the interacting model](#accessing-saved-items-relationship-for-the-interacting-model)
6. [**Testing**](#testing)
7. [**Changelog**](#changelog)
8. [**Contributing**](#contributing)
9. [**Security**](#security)
10. [**Credits**](#credits)
11. [**License**](#license)

Use Cases
---------

[](#use-cases)

1. Voting System (Upvoting and Downvoting)
2. Bookmarking System
3. Liking and Reaction System
4. Anything that requires a third party user to approve or reject.

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

[](#installation)

1. Install the package via composer:

    ```
    composer require toneflix-code/social-interactions
    ```
2. Publish resources (migrations and config files) \[Optional\]:

    - Config File

        ```
        php artisan vendor:publish --tag=social-interactions-config
        ```

        After publishing, the config file can be found in `config/social-interactions.php`
    - Migration Files

        ```
        php artisan vendor:publish --tag=social-interactions-migrations
        ```
3. Before running migrations, you may want to take a look at the `tables` config if you want to customize the table names used by the package. Finally. run the migrations with the following command:

    ```
    php artisan migrate
    ```
4. Done!

Package Discovery
-----------------

[](#package-discovery)

Laravel automatically discovers and publishes service providers but optionally after you have installed Laravel Fileable, open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package.

```
ToneflixCode\SocialInteractions\SocialInteractionsServiceProvider::class
```

Add the facade of this package to the $aliases array.

```
'SocialInteraction' => ToneflixCode\SocialInteractions\Facades\SocialInteraction::class
```

Configuration
-------------

[](#configuration)

If you published

Usage
-----

[](#usage)

For a model to be able to interact with other models, it has to be using the `ToneflixCode\SocialInteractions\Traits\CanSocialInteract` trait.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use ToneflixCode\SocialInteractions\Traits\CanSocialInteract;

class User extends Authenticatable
{
    use HasFactory;
    use CanSocialInteract;
}
```

Also the model which is to be intracted with will implement the `ToneflixCode\SocialInteractions\Traits\HasSocialInteractions` trait.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use ToneflixCode\SocialInteractions\Traits\HasSocialInteractions;

class Post extends Model
{
    use HasFactory;
    use HasSocialInteractions;
}
```

At this point you're are ready to begin creating social interactions with your models.

### Likes

[](#likes)

To leave a like, call the `leaveReaction` method on the model with the `CanSocialInteract` trait, passing the model with the `HasSocialInteractions` trait as the first parameter and either of `0`, `1`, `false`, `true` as the second. If a model is already liked, a second call will unlike the model. Likes are only available if the `enable_reactions` config property is set to `false`, otherwise this will set the reaction to the first reaction defined in the `available_reactions` config property.

1. Like

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $user->leaveReaction($post, true);
    ```
2. Unlike

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $user->leaveReaction($post, false);
    ```

#### Check if a model has been liked

[](#check-if-a-model-has-been-liked)

To check if a model has been liked, call the `isLiked` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the only parameter.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$liked = $post->isLiked($user);
```

### Dislikes

[](#dislikes)

To leave a dislike, call the `leaveReaction` method on the model with the `CanSocialInteract` trait, passing the model with the `HasSocialInteractions` trait as the first parameter and `dislikee` as the second. If a model is already disliked, a second call will undislike the model. Dislikes are only available if the `enable_dislikes` config property is set to `true`.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$reaction = $user->leaveReaction($post, 'dislike');
```

#### Check if a model has been disliked

[](#check-if-a-model-has-been-disliked)

To check if a model has been disliked, call the `isDisliked` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the only parameter.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$disliked = $post->isDisliked($user);
```

### Reactions

[](#reactions)

Reactions can be enabled and available reactions can be set in the config file. To leave a reaction, call the `leaveReaction` method on the model with the `CanSocialInteract` trait, passing the model with the `HasSocialInteractions` trait as the first parameter and the desired reaction as the second.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$reaction = $user->leaveReaction($post, 'love');
```

```
$user = \App\Models\User::find(3);
$post = \App\Models\Post::find(2);

$reaction = $user->leaveReaction($post, 'haha');
```

#### Check if a model has been reacted to

[](#check-if-a-model-has-been-reacted-to)

To check if a model has been reacted to, call the `isReacted` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the only parameter.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$reacted = $post->isReacted($user);
```

### Votes

[](#votes)

To vote for a model, call the `giveVote` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the first parameter and either of `true` or `false` as the second. If a model is already voted and the `multiple_votes` config property is set to true, subsequent calls will add to the vote count of the model. By default, voted models can not be unvoted for, to allow unvotes, set the `enable_unvote` config property to `true`.

1. Vote

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->giveVote($user, true);
    ```
2. Unvote

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->giveVote($user, false);
    ```

#### Check if a model has been voted for

[](#check-if-a-model-has-been-voted-for)

To check if a model has been voted for, call the `isVoted` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the only parameter.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$voted = $post->isVoted($user);
```

### Saving

[](#saving)

To mark a model as saved, call the `toggleSave` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the first parameter and either of `true` or `false` as the second.

1. Save

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSave($user, true);
    ```
2. Unsave

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSave($user, false);
    ```

#### Check if a model has been saved

[](#check-if-a-model-has-been-saved)

To check if a model has been saved, call the `isSaved` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the only parameter.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$saved = $post->isSaved($user);
```

Optionally, you can pass the name of a list as a second parameter to check if the model has been saved to the list.

```
$user = \App\Models\User::find(1);
$post = \App\Models\Post::find(2);

$saved = $post->isSaved($user, 'default');
```

#### Saving to a list

[](#saving-to-a-list)

To save a model to a list, call the `toggleSaveToList` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the first parameter and either of `true` or `false` as the second and the `list name` as the third.

1. Save

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSaveToList($user, true, 'default');
    $reaction = $post->toggleSaveToList($user, true, 'reusable');
    ```
2. Unsave

    ```
    $user = \App\Models\User::find(1);
    $post = \App\Models\Post::find(2);

    $reaction = $post->toggleSaveToList($user, false, 'default');
    $reaction = $post->toggleSaveToList($user, false, 'reusable');
    ```

#### Retrieving your lists

[](#retrieving-your-lists)

To retrieve the names of all your saved lists, access the `saved_social_lists` property on the model with the `CanSocialInteract` trait. You get a collection with all the names.

```
$user = \App\Models\User::find(1);

$lists = $user->saved_social_lists;
```

#### Deleting lists

[](#deleting-lists)

To delete a saved list, call the `deleteSavedSocialList` method on the model with the `CanSocialInteract` trait, passing the name of the desired list to delete as the only parameter or `true` to delete all lists.

```
$user = \App\Models\User::find(1);

$lists = $user->deleteSavedSocialList('default');
```

OR

```
$user = \App\Models\User::find(1);

$lists = $user->deleteSavedSocialList(true);
```

### Accessing the interaction relationship

[](#accessing-the-interaction-relationship)

The interaction relationship can be accessed from the `socialInteractions` property or method (if you need finer grain control and access to the Eloquent builder instance) on the model with the `HasSocialInteractions` trait.

```
$post = \App\Models\Post::find(1);

$interactions = $post->socialInteractions;
```

OR

```
$post = \App\Models\Post::find(1);

$interactions = $post->socialInteractions()->orderBy('id')->paginate(10);
```

### Accessing the interactor relationship

[](#accessing-the-interactor-relationship)

The interactor relationship which represent the model (or user) that interacted with the model can be accessed from the `interactor` property or method (if you need finer grain control and access to the Eloquent builder instance) on the `SocialInteraction` model.

```
$post = \App\Models\Post::find(1);

$interactions = $post->socialInteractions;

foreach ($interactions as $interaction) {
    $interactor = $interaction->interactor;
}
```

### Accessing the interaction relationship for the interacting model

[](#accessing-the-interaction-relationship-for-the-interacting-model)

The interaction relationship for the interacting model can be accessed from the `socialInteracts` property or method (if you need finer grain control and access to the Eloquent builder instance) on the model with the `CanSocialInteract` trait.

```
$post = \App\Models\Post::find(1);

$interactions = $post->socialInteracts;
```

OR

```
$post = \App\Models\Post::find(1);

$interactions = $post->socialInteracts()->orderBy('id')->paginate(10);
```

### Get Model Interaction for a specific Interactor

[](#get-model-interaction-for-a-specific-interactor)

To get the model interaction, call the `modelInteraction` method on the model with the `HasSocialInteractions` trait, passing the model with the `CanSocialInteract` trait as the only parameter. Since the package uses a single model for all interactions, this will return the `SocialInteraction` model for the current model with the `HasSocialInteractions` trait.

```
$post = \App\Models\Post::find(1);
$user = \App\Models\User::find(1);

$interaction = $post->modelInteraction($user);
```

### Get Interaction Data

[](#get-interaction-data)

For convinience, the package also provides the `socialInteractionData` method on the model with the `HasSocialInteractions` trait to help you quickly get the interaction stats for the model as a Laravel collection, passing the model with the `CanSocialInteract` trait as the only parameter will also attach the interaction states for the interacting model.

```
$post = \App\Models\Post::find(1);

$data = $post->socialInteractionData();
```

Example Output:

```
Array[
    'votes' => 10,
    'likes' => 5,
    'dislikes' => 1,
    'reactions' => 7,
]
```

With Interactor:

```
$post = \App\Models\Post::find(1);
$user = \App\Models\User::find(3);

$data = $post->socialInteractionData($user);
```

Example Output:

```
Array[
    'votes' => 10,
    'likes' => 5,
    'dislikes' => 1,
    'reactions' => 7,
    'saved' => true,
    'voted' => true,
    'liked' => false,
    'reacted' => true,
    'ownvotes' => 1,
    'disliked' => false,
    'reaction' => 'love',
    'reaction_color' => 'red',
    'state_icons' => [
        'saved' => 'fas fa-bookmark',
        'voted' => 'fas fa-thumbs-up',
        'disliked' => 'far fa-thumbs-down',
        'reaction' => 'fas fa-heart',
    ],
]
```

### Accessing saved items relationship

[](#accessing-saved-items-relationship)

The saved items relationship can be accessed from the `socialInteractionSaves` property or method (if you need finer grain control and access to the Eloquent builder instance) on the model with the `HasSocialInteractions` trait.

```
$post = \App\Models\Post::find(1);

$saves = $post->socialInteractionSaves;
```

OR

```
$post = \App\Models\Post::find(1);

$saves = $post->socialInteractionSaves()->whereBetween('created_at', ['2024-00-12 11:22:01', '2024-07-12 11:22:01'])->paginate(10);
```

### Accessing saved items relationship for the interacting model

[](#accessing-saved-items-relationship-for-the-interacting-model)

The saved items relationship for the interacting model can be accessed from the `savedSocialInteracts` property or method (if you need finer grain control and access to the Eloquent builder instance) on the model with the `CanSocialInteract` trait.

```
$post = \App\Models\Post::find(1);

$saves = $post->savedSocialInteracts;
```

OR

```
$post = \App\Models\Post::find(1);

$saves = $post->savedSocialInteracts()->whereBetween('created_at', ['2024-00-12 11:22:01', '2024-07-12 11:22:01'])->paginate(10);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Toneflix Code](https://github.com/toneflix)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance70

Regular maintenance activity

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 86.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~45 days

Recently: every ~89 days

Total

10

Last Release

325d ago

PHP version history (2 changes)1.0.0PHP ^8.1|^8.2|^8.3

1.0.7PHP ^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/4638f9de973d94753ebff641af3009e1049064f9a6bd76fe87e58d0d8ddd7ca7?d=identicon)[3m1n3nc3](/maintainers/3m1n3nc3)

---

Top Contributors

[![3m1n3nc3](https://avatars.githubusercontent.com/u/52163001?v=4)](https://github.com/3m1n3nc3 "3m1n3nc3 (112 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

dislikesinteractlaravellikesreactionssavessocialsocial-interactionssocialbookmarklikedislikeinteractionsreactionstoneflix-codesavesinteractsocial-interactions

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/toneflix-code-social-interactions/health.svg)

```
[![Health](https://phpackages.com/badges/toneflix-code-social-interactions/health.svg)](https://phpackages.com/packages/toneflix-code-social-interactions)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
