PHPackages                             asseco-voice/laravel-inbox - 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. asseco-voice/laravel-inbox

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

asseco-voice/laravel-inbox
==========================

Laravel handling incoming communication

v3.1.0(2y ago)44.2k↑93.5%[3 PRs](https://github.com/asseco-voice/laravel-inbox/pulls)1MITPHPPHP ^8.1

Since Apr 1Pushed 1y ago5 watchersCompare

[ Source](https://github.com/asseco-voice/laravel-inbox)[ Packagist](https://packagist.org/packages/asseco-voice/laravel-inbox)[ RSS](/packages/asseco-voice-laravel-inbox/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (11)Used By (1)

[![](https://github.com/asseco-voice/art/raw/main/evil_logo.png)](https://see.asseco.com)

Laravel inbox
=============

[](#laravel-inbox)

Purpose of this package is to provide pattern-matching for incoming communication and executing custom callbacks if they match.

Credits to [BeyondCode](https://github.com/beyondcode/laravel-mailbox) for the initial codebase. The idea for this package later on substantially diverged from the original, leaving no alternative than to separate it as a new package.

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

[](#installation)

Require the package with `composer require asseco-voice/laravel-inbox`. Service provider will be registered automatically.

Usage
-----

[](#usage)

### Interface

[](#interface)

Before you start using the package, you need to have a class implementing a `CanMatch`interface so that package knows what will it validate regex against.

I.e. if you want to validate against 'from', you need to defined where to fetch that piece of information from.

```
class Message implements CanMatch
{
    ...
    public function getMatchedValues(string $matchBy): array
    {
        switch ($matchBy) {
            case 'from':                return [$this->from()];
            case 'subject':             return [$this->subject()];
            case 'something_custom':    return [$this->custom()];
            default:                    return [];
        }
    }
    ...
}
```

### Inbox API

[](#inbox-api)

`Inbox` is a class in which you provide regex patterns which you'd like to be matched before the given callback is executed.

I.e. the callback defined under `action()` will execute only if the `.*@gmail.com`pattern is matched:

```
$inbox = new Inbox();

$inbox
    ->from('{.*}@gmail.com')
    ->action(function (CanMatch $message) {
        Log::info("Message received");
    });
```

Patterns need to be surrounded within `{ }`.

- `from($pattern)` will target `from` field
- `to($pattern)` will target `to` field
- `cc($pattern)` will target `cc` field
- `bcc($pattern)` will target `bcc` field
- `subject($pattern)` will target `subject` field
- `setPattern($name, $pattern)` is created for every other use case you might need. I.e. `from($pattern)` is just a shorthand for `setPattern('from', $pattern)`.
- `meta([...])` for adding any other meta-data.
- `action(callable)` is a callback to be executed and takes object implementing a `CanMatch` interface as an only argument (can be omitted though).
- `matchEither()` will act as `OR` gate in case more than one pattern is defined. Default behavior is to match *all* patterns for a callback to execute.
- `priority($number)` will set inbox priority which will be taken into account *only* if `InboxGroup` is used.
- `run(CanMatch $message)` will take an instance of object implementing `CanMatch`interface and will return a bool of whether the inbox was hit or not. **This method must not be used when using inbox groups. They have their own `run()` method**.

### Inbox group API

[](#inbox-group-api)

Should you require multiple cases covered, there is also a higher level concept - `InboxGroup` which acts as a container for multiple inboxes, having a few fluent API methods as well.

- `add(Inbox $inbox)` will add an inbox to a group
- `continuousMatching()` will continue matching after a first match is hit. Default behavior is to stop after one inbox is matched.
- `fallback(callable)` will add a (non-mandatory) fallback which will execute if no inbox is hit.
- `run(CanMatch $message)` will take an instance of object implementing `CanMatch`interface and will (unlike inbox `run()` method) return an array of matched inboxes. Inboxes will be ran by priority.

More examples
=============

[](#more-examples)

Examples will cover cases using mail, but it can be adapted to any incoming communication.

Matching functions can be used to either provide an exact match (i.e. `from('exact@email.com')`) or providing a regex match which needs to be surrounded with curly braces `{ }` to be interpreted as such.

Example:

```
$inbox = new Inbox();

$inbox
    ->from('{.*}@gmail.com')
    ->to('{.*}@gmail.com')
    ->subject('Subject to match')
    ->action(function (CanMatch $email) {
        Log::info("Mail received");
    })
    ->matchEither()
    ->priority(10);
```

More examples with outcomes:

- having an exact match `from('your.mail@gmail.com')`:
    - only mails coming solely from `your.mail@gmail.com` will be matched.
- having a partial match `from('{.*}@gmail.com')`:
    - any gmail address will be matched like `someone@gmail.com` and `someone-else@gmail.com` will be matched, but `someone@yahoo.com` won't).
- having a partial match `from('your.name@{.*}')`:
    - same as last example, but this time the name is fixed and provider is flexible. It would match `your.name@gmail.com`, `your.name@yahoo.com`, but it wouldn't match `not.your.name@gmail.com`.
- having a full regex match: `from('{.*}')`:
    - accepts anything.

Group example:

```
public function receiveEmail($email){

    $inbox1 = ...;
    $inbox2 = ...;
    $inbox3 = ...;

    $group = new InboxGroup();

    $group
        ->add($inbox1)
        ->add($inbox2)
        ->add($inbox3)
        ->fallback(function (CanMatch $email) {
            Log::info("Fell back");
        })
        ->continuousMatching()
        ->run($email);
}
```

If you don't want to use groups, but a single inbox, you can call run method on it directly:

```
public function receiveEmail($email){

    $inbox = new Inbox();

    $inbox
        ->...
        ->...
        ->run($email);
}
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 77.5% 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 ~210 days

Recently: every ~250 days

Total

6

Last Release

817d ago

Major Versions

v0.1.0 → v1.0.02021-05-18

v1.0.0 → v2.0.02022-05-05

v2.1.0 → v3.0.02023-08-08

PHP version history (3 changes)v0.1.0PHP ^7.4 || ^8.0

v2.0.0PHP ^8.0

v3.0.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![Norgul](https://avatars.githubusercontent.com/u/11718157?v=4)](https://github.com/Norgul "Norgul (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![assefvisic](https://avatars.githubusercontent.com/u/60132037?v=4)](https://github.com/assefvisic "assefvisic (2 commits)")[![AkronimBlack](https://avatars.githubusercontent.com/u/39061674?v=4)](https://github.com/AkronimBlack "AkronimBlack (1 commits)")[![josip-milotic](https://avatars.githubusercontent.com/u/42002911?v=4)](https://github.com/josip-milotic "josip-milotic (1 commits)")[![ngaspari](https://avatars.githubusercontent.com/u/33628128?v=4)](https://github.com/ngaspari "ngaspari (1 commits)")

---

Tags

inboxlaravellaravel8packagepattern-matchingphpphplaravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asseco-voice-laravel-inbox/health.svg)

```
[![Health](https://phpackages.com/badges/asseco-voice-laravel-inbox/health.svg)](https://phpackages.com/packages/asseco-voice-laravel-inbox)
```

###  Alternatives

[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[salmanzafar/laravel-geocode

A Laravel Library to find Lat and Long of a given Specific Address

153.9k](/packages/salmanzafar-laravel-geocode)

PHPackages © 2026

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