PHPackages                             insomnicles/laraexpress - 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. insomnicles/laraexpress

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

insomnicles/laraexpress
=======================

A Laravel package for reactions, ratings, emoticons, and other custom expression types

022PHP

Since Aug 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/insomnicles/laraexpress)[ Packagist](https://packagist.org/packages/insomnicles/laraexpress)[ RSS](/packages/insomnicles-laraexpress/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laraexpress
-----------

[](#laraexpress)

A simple way of handling expressions, reactions and ratings in Laravel.

Features
--------

[](#features)

- Terminology

    - *ExpressionType*: a type of expression, reaction or rating (e.g. 1 to 5 stars, Like/Dislike)
    - *ExpressableModel*: a laravel model kind that *can* have expressions (e.g. 'App\\Models\\Image')
    - *Expressable Id*: id of a specific model of kind ExpressableModel (e.g. id=4)
    - *Expression*: expression value (e.g. 3 stars)
- Expression Features

    - Several build-in Expression types with discrete or gradient ranges
    - Custom expressions can be added
    - Expressable models (models that *can* have expressions) must be predefined in DB
    - Expressable models can have multiple expression types
        - E.g. Image model can have two expression types: like/dislike AND 5-star rating)
    - One user expression per expressable model-expression type pair
    - Only authenticated users can store expressions
    - Users are authorized to only update or delete their own expressions
- Pre-defined Expression Types

    - Applause
    - Like/Dislike
    - Hot - Cold discrete
    - Hot - Cold gradient
    - Cognitive: interesting, clear, confused
    - Emotive: Happy, Sad, Super Happy
    - Five Star
    - Michelin Stars: 1, 2 or 3 stars
    - Vote: in favor, against, abstain
    - ELO Chess Rating: 1200 or up

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

[](#installation)

```
composer require insomnicles/laraexpress
php artisan vendor:publish

```

Usage
-----

[](#usage)

- To define which models can have expressions of what expression type, add the following to a DB seeder:

```
ExpressableModel::create([
	'expressable_type' => 'App\Models\Image',
	'expression_type_id' => Xpress::FIVESTAR ]);

ExpressableModel::create([
	'expressable_type' => 'App\Models\Image',
	'expression_type_id' => Xpress::EMOTIVE ]);

```

- To create expressions/ratings, use the Express::express Facade:
    - Express::express($object, $type\_id, $expression)

```
$expr = Express::express($image, Xpress::FIVESTAR, Express::TWOSTARS);
$expr = Express::express($product, Xpress::FIVESTAR, Express::FIVESTARS);
$expr = Express::express($restaurant, Xpress::MICHELINSTAR, Express::ONEMICHELINSTARS);
$expr = Express::express($image, Xpress::LIKEDISLIKE, Express::LIKE);
$expr = Express::express($image, Xpress::HOTCOLDGRADIENT, 2.563);
$expr = Express::express($image, Xpress::EMOTIVE, Express::HAPPY);
$expr = Express::express($image, Xpress::EMOTIVE, Express::MAD);
$expr = Express::express($image, Xpress::COGNITIVE, Express::CONFUSING);
$expr = Express::express($image, Xpress::COGNITIVE, Express::INTERESTING);
$expr = Express::express($chessPlayer, Xpress::ELO, Express::GRANDMASTER);
$expr = Express::express($chessPlayer, Xpress::ELO, 2832);
$expr = Express::express($bill, Xpress::VOTE, Express::INFAVOR);

```

- To retrieve expression values and stats, use the Express::stats Facade:
    - Express::stats(String $expressable\_type, int $expressable\_id, int $expression\_type\_id)

```
$objectStats = Express::stats(5, 1, 6);

```

Creating Custom Types
---------------------

[](#creating-custom-types)

- To create a Custom Expression Type, do the following
    1. Add new Custom ExpressionType
        - Add record to ExpressionType Model via ExpressionTypes Seeder in DatabaseSeeder.php (or insert record into table)
        - Example: a custom type for expressing love

        ```
        ExpressionType::create([
            'id' => 11, 'description' => 'Love Rating from 1 to 5',
            'range_type' => 'int', 'min' => 1, 'max' => 5,
            'icons' => json_encode([    1 => 'icons/smallheart.png', 3 => 'icons/heart.png', 5 => 'icons/bigheart.png']),
            'labels' => json_encode([   1 => 'little love',  3 => 'love', 5 => 'looove' ])]);

        ```
    2. Add what models users can make custom type expressions to
        - Add records to ExpressableModel via ExpressableModelSeeder in DatabaseSeeder
        - Example: users can leave love expressions to the user and image models

        ```
        ExpressableModel::create([ 'id' => 4, 'expressable_type' => 'App\Models\User',   'expression_type_id' => 11 ]);
        ExpressableModel::create([ 'id' => 4, 'expressable_type' => 'App\Models\Image',  'expression_type_id' => 11 ]);

        ```
    3. Add constants for Facade Calls
        - Add constants, custom type name and expression values to Xpress.php

        ```
        const LOVERTG = 11;    // corresponds to id in expression_type_table
        const LTLLOVE = 1;
        const LOVE = 3;
        const LOOOVE = 5;

        ```
    4. Use Facades as above $expression = Express::express($image, Express::LOVERTG, Express::HUGELUV); $expression = Express::express($user, Express::LOVERTG, Express::LUV);

Examples of Definition of Pre-defined Expression Types
------------------------------------------------------

[](#examples-of-definition-of-pre-defined-expression-types)

- Michelin Stars

    - range\_type: int
    - min: 1
    - max: 3
    - names: \[ 1 =&gt; '1 Michelin Star', 2 =&gt; '2 Michelin Stars', 3 =&gt; '3 Michelin Stars' \]
    - icons: \[ 1 =&gt; '1-star.png', 2 =&gt; '2-stars.png', 3 =&gt; '3-stars.png' \]
- Voting

    - range\_type: int
    - min: 1
    - max: 2
    - names: \[ 1 =&gt; 'In Favor', 2 =&gt; 'Against' \]
    - icons: null
- Hot-Cold

    - range\_type: float
    - min: 1
    - max: 5
    - names: \[ 1 =&gt; 'Freezing', 2 =&gt; 'Cold', 3 =&gt; 'Medium', 4 =&gt; 'Warm', 5 =&gt; 'Hot' \]
    - icons: \[ 1 =&gt; 'freezing.png', 5 =&gt; 'hot.png' \]

Design Choices
--------------

[](#design-choices)

- Independence from rest of Laravel Application
    - i) facade call only (no use of eloquent)
    - ii) Use
        - If app is part of standalone Laravel project, use one Facade call only
        - If app is microservice, use rest routes only
    - PRO:
        - adding, removing, updating expressions is simpler in basic crud cases
        - updates to expression versions can't affect rest of app
        - can create independent expressions microservice in architectures with different languages and frameworks
        - integration with relational or noSQL databases is simpler: no changes to facade
    - CON: can't integrate with eloquent models and queries
        - makes querying expressions more cumbersome (two/three-step process) and potentially slower

License
-------

[](#license)

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 97.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/33817780aaaafb49d1fbf731fb22019f92ef4d8b7a97889d8993e28893d4f8ce?d=identicon)[insomnicles](/maintainers/insomnicles)

---

Top Contributors

[![insomnicles](https://avatars.githubusercontent.com/u/13597665?v=4)](https://github.com/insomnicles "insomnicles (45 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

laravelmicroservicephp

### Embed Badge

![Health badge](/badges/insomnicles-laraexpress/health.svg)

```
[![Health](https://phpackages.com/badges/insomnicles-laraexpress/health.svg)](https://phpackages.com/packages/insomnicles-laraexpress)
```

###  Alternatives

[symfony/polyfill-php72

Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions

4.8k674.7M31](/packages/symfony-polyfill-php72)[symfony/polyfill-intl-icu

Symfony polyfill for intl's ICU-related data and classes

2.6k251.4M96](/packages/symfony-polyfill-intl-icu)[nette/php-generator

🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.5 features.

2.2k64.2M574](/packages/nette-php-generator)[consolidation/site-process

A thin wrapper around the Symfony Process Component that allows applications to use the Site Alias library to specify the target for a remote call.

5345.3M8](/packages/consolidation-site-process)[sycho/flarum-profile-cover

Adds the ability to add a cover image to a profile.

1836.6k](/packages/sycho-flarum-profile-cover)

PHPackages © 2026

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