PHPackages                             narcisonunez/laravel-actionable-model - 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. [Database &amp; ORM](/categories/database)
4. /
5. narcisonunez/laravel-actionable-model

ActiveLibrary[Database &amp; ORM](/categories/database)

narcisonunez/laravel-actionable-model
=====================================

Allow actions in your laravel model

1.3.2(5y ago)129MITPHPPHP ^8.0

Since Mar 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/narcisonunez/laravel-actionable-model)[ Packagist](https://packagist.org/packages/narcisonunez/laravel-actionable-model)[ Docs](https://github.com/narcisonunez/laravel-actionable-model)[ GitHub Sponsors](https://github.com/narcisonunez)[ RSS](/packages/narcisonunez-laravel-actionable-model/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (7)Dependencies (6)Versions (8)Used By (0)

Allow actions in your laravel model
===================================

[](#allow-actions-in-your-laravel-model)

[![Latest Version on Packagist](https://camo.githubusercontent.com/361a0fa547db993098216a11013367e88164af4d9016ac6e53012d091d8bc47d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e61726369736f6e756e657a2f6c61726176656c2d616374696f6e61626c652d6d6f64656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/narcisonunez/laravel-actionable-model)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0780db01dd10d9754f9e98dfd711050b7ad4c93d48d1cd00fc681d2cafeff3ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6e61726369736f6e756e657a2f6c61726176656c2d616374696f6e61626c652d6d6f64656c2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/narcisonunez/laravel-actionable-model/actions?query=workflow%3ATests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/22853ad3f6eb3380b22ef4df2c89c8b6ed4d90877f20c31948561f878ec386ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6e61726369736f6e756e657a2f6c61726176656c2d616374696f6e61626c652d6d6f64656c2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/narcisonunez/laravel-actionable-model/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/d56e1faf1fe76f8ea5f7e5ebfd41c9de35da2b6bd355b8796770978052632960/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e61726369736f6e756e657a2f6c61726176656c2d616374696f6e61626c652d6d6f64656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/narcisonunez/laravel-actionable-model)

Allow models to perform or receive actions.

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

[](#installation)

You can install the package via composer:

```
composer require narcisonunez/laravel-actionable-model
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Narcisonunez\LaravelActionableModel\LaravelActionableModelServiceProvider" --tag="actionable-model-migrations"
php artisan migrate
```

Basic Setup
-----------

[](#basic-setup)

### Register your actions

[](#register-your-actions)

Add your action in your `AppServiceProvider`

```
use Narcisonunez\LaravelActionableModel\Facades\ActionableActionTypes;
use App\ActionTypes\KudosActionType;

ActionableActionTypes::register([
    'like',
    'kudos' => KudosActionType::class,
    'celebrate'
]);
```

You can implement your own class extending `ActionableTypeRecord` to add more logic to your records.
Ex. `icon` method to get that specific action type icon. Now, Any `kudos` action will have a method named `icon`.

Your actions will be used as dynamic method calls. See below.

### Create a new Actionable Action Type (OPTIONAL)

[](#create-a-new-actionable-action-type-optional)

```
php artisan actionable:type LikeActionType
```

### Add aliases to your models (OPTIONAL)

[](#add-aliases-to-your-models-optional)

Add your aliases in your `AppServiceProvider`

```
use App\Models\Cause;
use App\Models\User;
use Narcisonunez\LaravelActionableModel\Facades\ActionableModelAliases;

ActionableModelAliases::register([
    User::class => 'user',
    Cause::class => 'cause'
]);
```

Storing aliases in the database will prevent losing the reference if you move your models to another directory.

### Update existing models references to use the new alias

[](#update-existing-models-references-to-use-the-new-alias)

In case you already have data in the database, after adding the aliases you can run:

```
php artisan actionable:update-aliases // Update all the records
```

If you want just to update a specific value

```
php artisan actionable:update-aliases --from="App\\User" --to="App\\Models\\User"
```

To update all your existing records.

Traits
------

[](#traits)

A model that can perform actions you need to include:

```
// Imports
class User extends Authenticatable
{
    use ActionableModel;
    use CanPerformActions;
    ...
}
```

The model that can receive the actions must implement `CanBeActionable`

```
...
use Narcisonunez\LaravelActionableModel\Traits\ActionableModel;

class Cause extends Model implements CanBeActionable
{
    use ActionableModel;
    ...
}
```

Basic Usage
-----------

[](#basic-usage)

### Perform an action

[](#perform-an-action)

```
// You will use your actions as methods call.
$user->performActionOn($cause)->like();
$user->performActionOn($cause)->kudos();
$user->performActionOn($cause)->celebrate();
```

Check if the action was already made
------------------------------------

[](#check-if-the-action-was-already-made)

```
// returns False or an ActionableTypeRecord
$user->hasPerformedAction('like')->on($cause);
```

Toggle your actions
-------------------

[](#toggle-your-actions)

```
// remove if exists the action, otherwise creates a new like
$user->performActionOn($cause)->toggle('like');
// OR
// toggleACTIONTYPE
$user->performActionOn($cause)->toggleLike();
$user->performActionOn($cause)->toggleKudos();
$user->performActionOn($cause)->toggleCelebrate();
```

Manually delete an action (See Toggle above)
--------------------------------------------

[](#manually-delete-an-action-see-toggle-above)

```
if ($action  = $user->hasPerformedAction('like')->on($cause) ) {
    $action->delete();
}
```

Get all the actions
-------------------

[](#get-all-the-actions)

```
$user->actions;

// To help you out filtering your actions. You can use the actionsFilter method
$user->actionsFilter()->get();
$user->actionsFilter()->latest(10);
$user->actionsFilter()->given()->get();
$user->actionsFilter()->received()->get();
$user->actionsFilter()->ofType('like')->get();
$cause->actionsFilter()->by($user)->ofType('like')->get();
$cause->actionsFilter()->by($user)->ofType('like')->count();
```

#### - Available methods -

[](#--available-methods--)

MethodDescriptiongetReturns a collection of `ActionableTypeRecord`countReturns the number of recordsgivenFilters all the records where the current model performed the actionsreceivedFilters all the records where the current model received the actionsofTypeFilters by the actionTypebyFilters all the actions in the current model where the model passed to this method performed the actionlatestGet the collection sorted by the latest ones.### Actionable Record

[](#actionable-record)

The methods above will return a collection of `ActionableRecord`.
The access the owner or the actionable models, you can do it like this:

```
$actionRecord = $user->actionsFilter()->ofType('like')->get()->first();

$actionRecord->owner; // The model that performed the action
$actionRecord->actionable; // The model that received the action
$actionRecord->action; // Action that was performed. ex. like, kudos, celebrate, etc.
$actionRecord->type; // An alias to action
```

💖 Support the development
-------------------------

[](#-support-the-development)

**Do you like this project? Support it by donating**

- PayPal: [Donate](https://www.paypal.com/donate?hosted_button_id=AHCCCPMWR66YL)

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~3 days

Total

7

Last Release

1858d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6155516?v=4)[Narciso E. Núñez Arias](/maintainers/narcisonunez)[@narcisonunez](https://github.com/narcisonunez)

---

Top Contributors

[![narcisonunez](https://avatars.githubusercontent.com/u/6155516?v=4)](https://github.com/narcisonunez "narcisonunez (46 commits)")

---

Tags

laraveleloquentlikefavoritenarcisonunezlaravel-actionable-model

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/narcisonunez-laravel-actionable-model/health.svg)

```
[![Health](https://phpackages.com/badges/narcisonunez-laravel-actionable-model/health.svg)](https://phpackages.com/packages/narcisonunez-laravel-actionable-model)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[qirolab/laravel-reactions

Implement reactions (like, dislike, love, emotion etc) on Laravel Eloquent models.

19564.6k](/packages/qirolab-laravel-reactions)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

484.2k](/packages/giacomomasseron-laravel-models-generator)

PHPackages © 2026

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