PHPackages                             edram/laravel-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. edram/laravel-interactions

ActiveLibrary

edram/laravel-interactions
==========================

Laravel interactions package

0.0.2(1mo ago)04MITPHPPHP ^8.3

Since Jul 12Pushed 1mo agoCompare

[ Source](https://github.com/edram/laravel-interactions)[ Packagist](https://packagist.org/packages/edram/laravel-interactions)[ Docs](https://github.com/edram/laravel-interactions)[ RSS](/packages/edram-laravel-interactions/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

Laravel Interactions
====================

[](#laravel-interactions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ca447fb20ff62e396fc384e32cfd4419bf8b665baffd065d443dfef356a79d62/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656472616d2f6c61726176656c2d696e746572616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/edram/laravel-interactions)[![Tests](https://github.com/edram/laravel-interactions/actions/workflows/run-tests.yml/badge.svg)](https://github.com/edram/laravel-interactions/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/9b4127b7bdfa816829fa8e55fae00931d49566734c6a1532835582dd2c2e9df2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656472616d2f6c61726176656c2d696e746572616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/edram/laravel-interactions)

One polymorphic interaction system for likes, favorites, subscriptions, follows, votes, and custom actions.

AI skill
--------

[](#ai-skill)

Install the package usage skill to give your coding agent the public APIs, setup rules, and examples from this repository:

```
npx skills@latest add edram/laravel-interactions
```

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

[](#installation)

```
composer require edram/laravel-interactions
php artisan vendor:publish --tag="laravel-interactions-config"
php artisan vendor:publish --tag="laravel-interactions-migrations"
php artisan migrate
```

Set the default actor model used by relations such as `likers()`, `followers()`, `subscribers()`, and `voters()`:

```
// config/laravel-interactions.php
'default_actor' => App\Models\User::class,
```

The `key_type` configuration supports `bigint`, `uuid`, and `ulid`. Configure it before running the migration. Actors and interactables stored in the same interactions table must use the same key type.

Model setup
-----------

[](#model-setup)

Actors use `Interacts`. Targets use `Interactable`. A model such as User that can both create and receive interactions uses both traits.

```
use Edram\LaravelInteractions\Concerns\Interactable;
use Edram\LaravelInteractions\Concerns\Interacts;

class User extends Authenticatable
{
    use Interactable;
    use Interacts;
}

class Post extends Model
{
    use Interactable;
}

class Comment extends Model
{
    use Interactable;
}
```

Both sides are polymorphic. A User, Team, or any other Eloquent model using `Interacts` can act on any model using `Interactable`.

For a smaller model API, combine the core concerns with only the semantic concerns the model needs:

```
use Edram\LaravelInteractions\Concerns\Actor\Follows;
use Edram\LaravelInteractions\Concerns\Actor\HasInteractions;
use Edram\LaravelInteractions\Concerns\Actor\Likes;
use Edram\LaravelInteractions\Concerns\Target\HasFollowers;
use Edram\LaravelInteractions\Concerns\Target\HasLikers;
use Edram\LaravelInteractions\Concerns\Target\ReceivesInteractions;

class User extends Authenticatable
{
    use HasInteractions;
    use Follows;
    use Likes;
    use ReceivesInteractions;
    use HasFollowers;
}

class Post extends Model
{
    use ReceivesInteractions;
    use HasLikers;
}
```

Actor semantic concerns require `HasInteractions`. Target semantic concerns require `ReceivesInteractions`. `Interacts` and `Interactable` remain the convenient all-in-one alternatives.

Actor models
------------

[](#actor-models)

Any Eloquent model using `Interacts`, or `HasInteractions` with selected Actor concerns, can initiate interactions. `default_actor` is not an allowlist; it only chooses the related model when a target-side relation omits its Actor class.

```
class Team extends Model
{
    use Interactable;
    use Interacts;
}

$user->like($post);
$team->like($post);

$post->likers()->get();            // User from default_actor
$post->likers(Team::class)->get(); // Team

$user->follow($team);
$team->followers()->get();         // User from default_actor
$team->followers(Team::class)->get();
```

A direct Eloquent relation returns one Actor model type. Query interaction records and eager load the polymorphic `actor` relation when all types are required:

```
$likes = $post->receivedInteractions('like')
    ->with('actor')
    ->get();

$actors = $likes->pluck('actor')->filter();
```

When no Actor class is passed, the package resolves `default_actor` and then falls back to `auth.providers.users.model`. Pass the class explicitly to override either default.

Built-in interactions
---------------------

[](#built-in-interactions)

InteractionActor APITarget APILike`like`, `unlike`, `toggleLike`, `hasLiked`, `likes`, `likedItems``isLikedBy`, `likers`, `likersFor`Favorite`favorite`, `unfavorite`, `toggleFavorite`, `hasFavorited`, `favorites`, `favoriteItems``isFavoritedBy`, `favoriters`Subscribe`subscribe`, `unsubscribe`, `toggleSubscribe`, `hasSubscribed`, `subscriptions`, `subscribedItems``isSubscribedBy`, `subscribers`Follow`follow`, `unfollow`, `toggleFollow`, `isFollowing`, `following``isFollowedBy`, `followers`Vote`vote`, `upvote`, `downvote`, `cancelVote`, `hasVoted`, `votes``isVotedBy`, `voters`, `upvoters`, `downvoters`, `totalVotes````
$user->like($post);
$user->unlike($post);
$user->toggleLike($post);
$user->hasLiked($post);
$post->isLikedBy($user);
$post->likers;
$user->likedItems(Post::class)->paginate();

$user->favorite($post);
$user->unfavorite($post);
$post->favoriters;

$user->subscribe($post);
$user->unsubscribe($post);
$post->subscribers;

$user->follow($anotherUser);
$user->unfollow($anotherUser);
$user->following;
$anotherUser->followers;

$user->upvote($post);
$user->downvote($post, 3);
$user->vote($post, 5);
$user->cancelVote($post);
$post->voters;
$post->upvoters;
$post->downvoters;
$post->totalVotes();
```

`like`, `favorite`, `subscribe`, and `follow` are idempotent. Calling them repeatedly does not create duplicate records. A vote uses one record per actor and target; changing direction or weight updates that record.

To query a non-default actor model, pass its class explicitly:

```
$post->likersFor(Team::class)->paginate();
$post->interactors('bookmark', Team::class)->get();
```

Custom interactions
-------------------

[](#custom-interactions)

Custom action names are lowercase slugs up to 64 characters. Strings and string-backed enums are accepted.

```
$interaction = $user->interact(
    $post,
    'bookmark',
    metadata: ['folder' => 'reading'],
);

$user->hasInteracted($post, 'bookmark');
$user->toggleInteraction($post, 'bookmark');
$user->uninteract($post, 'bookmark');

$user->interactions('bookmark')->get();
$post->receivedInteractions('bookmark')->with('actor')->get();
$user->interactedItems('bookmark', Post::class)->paginate();
$post->interactors('bookmark', User::class)->paginate();
```

Use the optional signed integer `value` for weighted actions and `metadata` for additional structured data.

Feed status
-----------

[](#feed-status)

Attach several interaction states to a model, collection, or paginator with one interaction query:

```
$posts = Post::paginate();

$user->attachInteractionStatus($posts, ['like', 'favorite', 'vote']);

$posts[0]->interaction_status;
// ['like' => true, 'favorite' => null, 'vote' => -1]
```

`null` means no interaction exists, `true` means an interaction without a value exists, and an integer is the stored value.

Events and deletion
-------------------

[](#events-and-deletion)

The package dispatches these events only when persistence actually changes:

- `Edram\LaravelInteractions\Events\InteractionCreated`
- `Edram\LaravelInteractions\Events\InteractionUpdated`
- `Edram\LaravelInteractions\Events\InteractionDeleted`

Hard-deleting an actor or interactable removes its interactions. Soft deletion preserves them until the model is force deleted.

Development
-----------

[](#development)

```
composer test
composer analyse
composer format
composer validate --strict
```

License
-------

[](#license)

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

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

2

Last Release

49d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14024542?v=4)[edram](/maintainers/edram)[@edram](https://github.com/edram)

---

Top Contributors

[![edram](https://avatars.githubusercontent.com/u/14024542?v=4)](https://github.com/edram "edram (5 commits)")

---

Tags

laravelinteractions

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/edram-laravel-interactions/health.svg)

```
[![Health](https://phpackages.com/badges/edram-laravel-interactions/health.svg)](https://phpackages.com/packages/edram-laravel-interactions)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3365.5M359](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.1k6.4M360](/packages/laravel-ai)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k59.5M714](/packages/laravel-scout)[spatie/laravel-health

Monitor the health of a Laravel application

89313.5M195](/packages/spatie-laravel-health)[illuminate/queue

The Illuminate Queue package.

20433.5M1.9k](/packages/illuminate-queue)[api-platform/laravel

API Platform support for Laravel

58190.1k22](/packages/api-platform-laravel)

PHPackages © 2026

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