PHPackages                             goomcoom/laravel-messages - 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. goomcoom/laravel-messages

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

goomcoom/laravel-messages
=========================

Sometimes you may wish to return responses with some extra messages informing the user of what happened. This package provides a fluent interface to add messages from anywhere within in your code base and gracefully add them to your JSON responses.

1.0.0(5y ago)05MITPHPPHP &gt;=5.6CI failing

Since Jun 17Pushed 5y agoCompare

[ Source](https://github.com/goomcoom/laravel-messages)[ Packagist](https://packagist.org/packages/goomcoom/laravel-messages)[ RSS](/packages/goomcoom-laravel-messages/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Laravel Messages
================

[](#laravel-messages)

Sometimes you may wish to return responses with some extra messages informing the user of what happened. This package provides a fluent interface to add messages from anywhere within in your code base and gracefully add them to your JSON responses.

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

[](#installation)

Install the package using composer.

```
$ composer require goomcoom/laravel-messages
```

The service provider and facade are registered automatically, but you may do so manually by adding them to the app config.

```
// config/app.php

[
    'providers' => [
        // ...
        GoomCoom\Messages\MessagesServiceProvider::class,
    ],

    'aliases' => [
        // ...
        'Messages' => GoomCoom\Messages\Facades\Messages::class,
    ],
];
```

Config
------

[](#config)

To publish the config file you may use the following command

```
$ php artisan vendor:publish --tag=goomcoom-laravel-messages
```

The config file holds the bags that are available for accepting messages which are fully customizable.

```
// config/goomcoom-laravel-messages.php

return [
    /**
     * –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     * Bags
     * –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     * These are the bags that messages can be added to.
     */

    'bags' => [
        'error',
        'info',
        'success',
        'warning',
    ],
];
```

Adding messages to responses
----------------------------

[](#adding-messages-to-responses)

If you would like the messages to the added to the response automatically, you may use the `AddMessagesToResponse`middleware. The middleware checks if there are any messages and adds them to the response's meta content. For information on using middleware please refer to the official [documentation](https://laravel.com/docs/7.x/middleware).

```
// The messages are added to the response's meta object

{
    data: {
        ...
    },
    meta: {
        ...
        messages: {
            error: [
                'Resource 532 was not updated',
            ],
            info: [
                'We did something you might not have expected'
            ]
        }
    }
}

```

The middleware also checks if the response has a message property and appends the message to the `meta.messages.error` array.

```
// The response message is appended to the error messages array

{
    message: 'Somethig went wrong.',
    meta: {
        messages: {
            error: [
                'Resource 532 was not updated',
                'Something went wrong.'
            ],
        }
    }
}

```

### Adding messages

[](#adding-messages)

The first argument is the message bag that the messages are meant to be added to. We use the splat operator to gather messages, so you may add multiple comma-separated messages at once.

```
    Messages::add('error', 'Cannot do that!', 'Something went wrong.');
    Messages::add('info', 'Something else happened.');

    /*
        {
            ...
            meta: {
                messages: {
                    error: [
                        'Cannot do that!',
                        'Something went wrong.'
                    ],
                    info: [
                        'Something else happened.'
                    ]
                }
            }
        }
    */
```

It's worth noting that messages are not duplicated within a category.

### Getting a bag

[](#getting-a-bag)

The package uses laravel's [MessageBag](https://laravel.com/api/7.x/Illuminate/Support/MessageBag.html) class to categorise the messages. You may retrieve a specific bag using the `getBag` method.

```
// Returns Illuminate/Support/MessageBag with "warning" messages
Messages::getBag('warning');
```

### Getting all messages

[](#getting-all-messages)

You may also retrieve all the messages as an associative array with the messages grouped by their category by using the `getAll` method.

```
Messages::getAll();

/*
    [
        'error' => [ ... ],
        'info' => [ ... ],
        'success' => [ ... ],
        'warning' => [ ... ],
    ]
*/
```

### Checking if any messages have been added

[](#checking-if-any-messages-have-been-added)

You may check if any messages have been added by using the `hasAny` method.

```
// Returns boolean
Messages::hasAny();
```

### Removing messages

[](#removing-messages)

You may remove messages from a specific bag by using the `remove` method.

```
// Removes all messages from the success bag.
Messages::remove('success', '*');

// Removes the "To be removed" & "Also to be removed" messages from the error bag'
Messages::remove('error', 'To be removed', 'Also to be removed');
```

### Resetting all message bags

[](#resetting-all-message-bags)

You may reset all message bags by calling the `reset` method.

```
// Removes all messages
Messages::reset();
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

2162d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a88243d718bea9e98d2a5d62ab33e6b303d483365941707f41a4f2e386a7bf82?d=identicon)[goomcoom](/maintainers/goomcoom)

---

Top Contributors

[![simonmsara](https://avatars.githubusercontent.com/u/18265324?v=4)](https://github.com/simonmsara "simonmsara (30 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/goomcoom-laravel-messages/health.svg)

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

###  Alternatives

[m1/env

Env is a lightweight library bringing .env file parser compatibility to PHP. In short - it enables you to read .env files with PHP.

6412.0M21](/packages/m1-env)[roave/psalm-html-output

Psalm HTML Output

23312.0k1](/packages/roave-psalm-html-output)[pear/system_daemon

A port of the PEAR class to create Daemons with pure PHP

11139.9k1](/packages/pear-system-daemon)[mateffy/laravel-codebase-mcp

An MCP server to give Cursor, Aider, etc. the ability to introspect your Laravel codebase directly, by querying for your models, views, routes and classes without raw file search.

201.1k](/packages/mateffy-laravel-codebase-mcp)

PHPackages © 2026

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