PHPackages                             aichadigital/laravel-mustache-resolver - 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. aichadigital/laravel-mustache-resolver

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

aichadigital/laravel-mustache-resolver
======================================

Framework-agnostic, fully testable, SOLID-compliant mustache template resolver for PHP applications with first-class Laravel integration

v1.1.1(5mo ago)019[3 PRs](https://github.com/AichaDigital/mustache/pulls)AGPL-3.0-or-laterPHPPHP ^8.2CI passing

Since Dec 9Pushed 2mo agoCompare

[ Source](https://github.com/AichaDigital/mustache)[ Packagist](https://packagist.org/packages/aichadigital/laravel-mustache-resolver)[ Docs](https://github.com/AichaDigital/mustache)[ GitHub Sponsors](https://github.com/AichaDigital)[ RSS](/packages/aichadigital-laravel-mustache-resolver/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (9)Used By (0)

Laravel Mustache Resolver
=========================

[](#laravel-mustache-resolver)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e1d7231aa10e9ecfcf308c093bec5ca0bd69a5c257b18c59a5bc6d9b7a43c183/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61696368616469676974616c2f6c61726176656c2d6d757374616368652d7265736f6c7665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aichadigital/laravel-mustache-resolver)[![Tests](https://camo.githubusercontent.com/f4d20a705f89bbeac2e0e0144b8530479b78a128b0c22b75da20dc3bf0239d42/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f41696368614469676974616c2f6d757374616368652f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/AichaDigital/mustache/actions?query=workflow%3ATests+branch%3Amain)[![Coverage](https://camo.githubusercontent.com/caa65b93249c9156a147985487e680973e2f109fd31101ef932a50bb9c480fd6/68747470733a2f2f636f6465636f762e696f2f67682f41696368614469676974616c2f6d757374616368652f67726170682f62616467652e737667)](https://codecov.io/gh/AichaDigital/mustache)[![Code Style](https://camo.githubusercontent.com/390f3b0a7b9014689dcdb9703a5aaf1da80b5a64a48ab49fa2b255dcee4fbc95/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f41696368614469676974616c2f6d757374616368652f636f64652d7374796c652e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/AichaDigital/mustache/actions?query=workflow%3A%22Code+Style%22+branch%3Amain)[![PHPStan](https://camo.githubusercontent.com/9a2ff581f1dde60b0f9d05dfbb4d90b41bc6a7aa9c3db879fb3380ea0a94fc3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f41696368614469676974616c2f6d757374616368652f7068707374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d7068707374616e267374796c653d666c61742d737175617265)](https://github.com/AichaDigital/mustache/actions?query=workflow%3APHPStan+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/2dec3246a6229851213c4e6cd37d3050df0953253e16d00a617218cd2c1cd528/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61696368616469676974616c2f6c61726176656c2d6d757374616368652d7265736f6c7665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aichadigital/laravel-mustache-resolver)[![PHP Version](https://camo.githubusercontent.com/54e5bf4454ad2f713558280255972baf90e48685bd672631a5c4d26d310246b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f61696368616469676974616c2f6c61726176656c2d6d757374616368652d7265736f6c7665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aichadigital/laravel-mustache-resolver)[![Laravel Version](https://camo.githubusercontent.com/ba7dc47b7ca4d3828169e287e5e3fa5db1fca8787b7611efd98d71f059fb3c8d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31302e7825323025374325323031312e7825323025374325323031322e782d7265643f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aichadigital/laravel-mustache-resolver)[![License](https://camo.githubusercontent.com/175c61279712b7ad522c4f9a4d91e045d0b71e74982162de8d4f091a9d9e9049/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61696368616469676974616c2f6c61726176656c2d6d757374616368652d7265736f6c7665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aichadigital/laravel-mustache-resolver)

A framework-agnostic, fully testable, SOLID-compliant mustache template resolver for PHP applications with first-class Laravel integration.

Features
--------

[](#features)

- **Simple field resolution**: `{{User.name}}`
- **Relation navigation**: `{{User.department.manager.name}}`
- **Dynamic fields**: `{{Device.$manufacturer.field_parameter}}`
- **Collection access**: `{{User.posts.0.title}}`, `{{User.addresses.*.city}}`
- **Built-in functions**: `{{now()}}`, `{{format(User.date, 'Y-m-d')}}`
- **Null coalescing**: `{{User.nickname ?? 'Anonymous'}}`
- **Framework-agnostic core** with optional Laravel integration
- **100% testable** without database

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10.x, 11.x, or 12.x (optional)

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

[](#installation)

```
composer require aichadigital/laravel-mustache-resolver
```

### Laravel

[](#laravel)

The package auto-discovers the service provider. Optionally publish the config:

```
php artisan vendor:publish --tag="mustache-resolver-config"
```

### Standalone (without Laravel)

[](#standalone-without-laravel)

```
use AichaDigital\MustacheResolver\Core\MustacheResolver;
use AichaDigital\MustacheResolver\Core\Parser\MustacheParser;
use AichaDigital\MustacheResolver\Core\Pipeline\PipelineBuilder;
use AichaDigital\MustacheResolver\Cache\NullCache;

$resolver = new MustacheResolver(
    new MustacheParser(),
    PipelineBuilder::create()->build(),
    new NullCache()
);
```

Usage
-----

[](#usage)

### Basic Usage with Laravel Facade

[](#basic-usage-with-laravel-facade)

```
use AichaDigital\MustacheResolver\Laravel\Facades\Mustache;

$template = "Hello, {{User.name}}! Your email is {{User.email}}.";
$user = User::find(1);

$result = Mustache::translate($template, $user);

if ($result->isSuccess()) {
    echo $result->getTranslated();
    // "Hello, John! Your email is john@example.com."
}
```

### Relation Navigation

[](#relation-navigation)

```
$template = "Manager: {{User.department.manager.name}}";
$result = Mustache::translate($template, $user);
```

### Collection Access

[](#collection-access)

```
// Access by index
$template = "First post: {{User.posts.0.title}}";

// Access first/last
$template = "Latest: {{User.posts.last.title}}";

// Wildcard (returns array)
$template = "All cities: {{User.addresses.*.city}}";
```

### With Variables

[](#with-variables)

```
$template = "Report for {{$period}}: {{User.name}}";
$result = Mustache::translate($template, $user, ['period' => '2024-Q1']);
```

### Batch Processing

[](#batch-processing)

```
$templates = [
    "Name: {{User.name}}",
    "Email: {{User.email}}",
    "Department: {{User.department.name}}",
];

$results = Mustache::translateBatch($templates, $user);
```

### Non-strict Mode

[](#non-strict-mode)

```
// Missing fields return empty string instead of failing
$result = Mustache::translate($template, $user, [], strict: false);
```

Configuration
-------------

[](#configuration)

```
// config/mustache-resolver.php
return [
    'strict' => true,           // Throw on unresolvable mustaches
    'keep_unresolved' => false, // Keep mustaches if not resolved (non-strict)

    'cache' => [
        'enabled' => false,
        'ttl' => 3600,
    ],

    'security' => [
        'max_depth' => 10,
        'blacklisted_attributes' => ['password', 'remember_token'],
    ],
];
```

Custom Resolvers
----------------

[](#custom-resolvers)

```
use AichaDigital\MustacheResolver\Contracts\ResolverInterface;

class CustomResolver implements ResolverInterface
{
    public function supports(TokenInterface $token, ContextInterface $context): bool
    {
        return $token->getPrefix() === 'Custom';
    }

    public function resolve(TokenInterface $token, ContextInterface $context): mixed
    {
        // Your resolution logic
    }

    public function priority(): int
    {
        return 150; // Higher than built-in resolvers
    }

    public function name(): string
    {
        return 'custom';
    }
}
```

Register in config:

```
'resolvers' => [
    \App\Resolvers\CustomResolver::class,
],
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [AichaDigital](https://github.com/AichaDigital)
- [All Contributors](../../contributors)

License
-------

[](#license)

The AGPL-3.0-or-later License. Please see [License File](LICENSE) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance80

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.2% 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

3

Last Release

152d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a4694c48c325d3dfbc4c43d97c2617f9317d7a447971750c338f943a88bd164?d=identicon)[abkrim](/maintainers/abkrim)

---

Top Contributors

[![abkrim](https://avatars.githubusercontent.com/u/1238625?v=4)](https://github.com/abkrim "abkrim (20 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laraveleloquenttemplatemustacheresolverplaceholdersAichaDigital

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/aichadigital-laravel-mustache-resolver/health.svg)

```
[![Health](https://phpackages.com/badges/aichadigital-laravel-mustache-resolver/health.svg)](https://phpackages.com/packages/aichadigital-laravel-mustache-resolver)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)

PHPackages © 2026

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