PHPackages                             aboleon/metaframework-dictionnaries - 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. aboleon/metaframework-dictionnaries

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

aboleon/metaframework-dictionnaries
===================================

Dictionnaries management package for MetaFramework

1.x-dev(1mo ago)00MITPHPPHP ^8.3CI failing

Since Mar 18Pushed 1mo agoCompare

[ Source](https://github.com/aboleon/metaframework-dictionnaries)[ Packagist](https://packagist.org/packages/aboleon/metaframework-dictionnaries)[ RSS](/packages/aboleon-metaframework-dictionnaries/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelogDependencies (8)Versions (1)Used By (0)

MetaFramework Dictionnaries
===========================

[](#metaframework-dictionnaries)

[![Tests](https://github.com/aboleon/metaframework-dictionnaries/actions/workflows/tests.yml/badge.svg)](https://github.com/aboleon/metaframework-dictionnaries/actions)[![codecov](https://camo.githubusercontent.com/a49b59e5f56e85a70be3b4c968dae8fb0c3ab26f50f12dae2209857f844c159d/68747470733a2f2f636f6465636f762e696f2f67682f61626f6c656f6e2f6d6574616672616d65776f726b2d64696374696f6e6e61726965732f67726170682f62616467652e737667)](https://codecov.io/gh/aboleon/metaframework-dictionnaries)[![Latest Version on Packagist](https://camo.githubusercontent.com/776b4dab2cf0d497a088f5fea387b6ce540cff865aaf25c89340aa4f9392f9c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61626f6c656f6e2f6d6574616672616d65776f726b2d64696374696f6e6e61726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aboleon/metaframework-dictionnaries)[![Total Downloads](https://camo.githubusercontent.com/f727efb49fec621bebecd731914ae5c745be6d3d3fd73e1f161ffc865c2e261f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61626f6c656f6e2f6d6574616672616d65776f726b2d64696374696f6e6e61726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aboleon/metaframework-dictionnaries)[![PHP Version](https://camo.githubusercontent.com/7fa249fcee78e0faaff0b0baf8afbb8dfc0273c97878c9c73bb6d5e11ad21433/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f61626f6c656f6e2f6d6574616672616d65776f726b2d64696374696f6e6e61726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aboleon/metaframework-dictionnaries)[![License](https://camo.githubusercontent.com/1d116578d5faf3dc697e7507c9aca99f645b32936eec71510f1e40059781bc44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61626f6c656f6e2f6d6574616672616d65776f726b2d64696374696f6e6e61726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aboleon/metaframework-dictionnaries)

`aboleon/metaframework-dictionnaries` is a Laravel package for managing dictionaries and dictionary entries.

It is not restricted to "MetaFramework applications". It can be installed in any Laravel app, while relying on MetaFramework packages as technical dependencies.

It provides:

- Admin routes/controllers/views for dictionaries and entries.
- Support for `simple`, `meta`, and `custom` dictionary types.
- Translation-aware storage and rendering (based on `mfw.translatable.multilang`).
- Cached accessor helpers to read dictionary values in app code.
- Configurable route prefix/name/middleware and configurable backend layout component.

What The Package Manages
------------------------

[](#what-the-package-manages)

Two entities:

- `Dictionnary` (`dictionnaries` table): defines a dictionary (`slug`, `type`, `name`).
- `DictionnaryEntry` (`dictionnary_entries` table): entries attached to a dictionary, with optional hierarchy (`parent`) and optional extra payload (`custom`).

Dictionary types:

- `simple`: flat entries list.
- `meta`: parent entries with nested sub-entries.
- `custom`: same storage with optional custom translatable/custom fields via subclass extension.

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

[](#requirements)

- PHP `^8.3`
- Laravel `^11.0|^12.0`
- `aboleon/metaframework`
- `yajra/laravel-datatables`

`aboleon/metaframework-inputable` and `aboleon/metaframework-support` are pulled transitively by `aboleon/metaframework`.

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

[](#installation)

```
composer require aboleon/metaframework-dictionnaries
```

Service provider is auto-discovered:

- `MetaFramework\Dictionnaries\DictionnariesServiceProvider`

Publishables
------------

[](#publishables)

Publish what you need:

```
php artisan vendor:publish --tag=mfw-dictionnaries-config
php artisan vendor:publish --tag=mfw-dictionnaries-migrations
php artisan vendor:publish --tag=mfw-dictionnaries-views
php artisan vendor:publish --tag=mfw-dictionnaries-lang
```

Then run migrations:

```
php artisan migrate
```

### Native Vs Published Resources

[](#native-vs-published-resources)

The package is designed to work in both modes:

- Native package resources (no publish).
- App-copied resources (after `vendor:publish`).

Resolution order:

- Views: `resources/views/vendor/mfw-dictionnaries` first, package views fallback.
- Translations: `lang/vendor/mfw-dictionnaries` first, package translations fallback.

If the package ships public assets in future versions, they can be published with:

```
php artisan vendor:publish --tag=mfw-dictionnaries-assets
```

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

[](#configuration)

Config file: `config/mfw-dictionnaries.php`

```
return [
    'layout_component' => 'mfw-dictionnaries::layout',

    'routes' => [
        'middleware' => ['web'],
        'prefix' => null,
        'name_prefix' => 'mfw.',
    ],

    'entry_subclasses_namespace' => 'App\\Models\\DictionnaryEntry',
];
```

### Layout Bridge

[](#layout-bridge)

Package views do not hardcode ``. They render through a dynamic component:

- `config('mfw-dictionnaries.layout_component')`

Example using app layout component:

```
'layout_component' => 'backend-layout',
```

Routing
-------

[](#routing)

Routes are grouped with:

- middleware: `mfw-dictionnaries.routes.middleware`
- prefix: `mfw-dictionnaries.routes.prefix` (fallback to `mfw`)
- name prefix: `mfw-dictionnaries.routes.name_prefix` (default `mfw.`, accepts `panel` or `panel.`)

Main route names:

- `mfw.dictionnary.index`
- `mfw.dictionnary.create`
- `mfw.dictionnary.store`
- `mfw.dictionnary.edit`
- `mfw.dictionnary.update`
- `mfw.dictionnary.destroy`
- `mfw.dictionnary.entries.index`
- `mfw.dictionnary.entries.create`
- `mfw.dictionnary.entries.store`
- `mfw.dictionnaryentry.edit`
- `mfw.dictionnaryentry.update`
- `mfw.dictionnaryentry.destroy`
- `mfw.dictionnaryentry.subentry`
- `mfw.dictionnary.mass-delete`

Multilang Behavior
------------------

[](#multilang-behavior)

Behavior depends on:

- `config('mfw.translatable.multilang')`

Where it is defined (host app):

- `config/mfw.php` under `translatable.multilang` (or equivalent merged `mfw` config).

Example configuration:

```
// config/mfw.php
return [
    'translatable' => [
        'multilang' => true, // or false
        'locales' => ['fr', 'bg'],
        'active_locales' => ['fr', 'bg'],
    ],
];
```

When `true`:

- Inputs are processed as localized arrays (`name[fr]`, `name[bg]`, ...).
- Sorting for entries uses JSON locale extraction with `app()->getLocale()`.

Request payload example (`multilang = true`):

```
[
    'name' => [
        'fr' => 'Pays',
        'bg' => 'Държави',
    ],
    'slug' => 'countries',
    'type' => 'simple',
]
```

When `false`:

- Inputs are processed as single values (`name`).
- Sorting uses plain `name` column.
- Models still read legacy JSON-formatted names safely (fallback locale or first available value).

Request payload example (`multilang = false`):

```
[
    'name' => 'Countries',
    'slug' => 'countries',
    'type' => 'simple',
]
```

Important cache note:

- `MetaFramework\Accessors\Locale::multilang()` is cached (`mfw.multilang`).
- After toggling config, clear cache:

```
php artisan cache:forget mfw.multilang
```

Using The Accessor API
----------------------

[](#using-the-accessor-api)

Class: `MetaFramework\Dictionnaries\Accessors\Dictionnaries`

Example:

```
use MetaFramework\Dictionnaries\Accessors\Dictionnaries;

// Fetch dictionary model by slug (cached forever)
$dictionary = Dictionnaries::dictionnary('countries');

// Flat select values: [id => label]
$values = Dictionnaries::selectValues('countries');

// Meta select values:
// [parentId => ['name' => 'Group', 'values' => [entryId => 'Label']]]
$metaValues = Dictionnaries::selectValues('service_family');

// Helpers
$title = Dictionnaries::title('countries');
$type = Dictionnaries::type('countries'); // simple|meta|custom
$entry = Dictionnaries::entry('countries', 12);

// Clear cache for one dictionary slug
Dictionnaries::reset('countries');
```

Usage Example In Blade
----------------------

[](#usage-example-in-blade)

```

```

Custom Dictionary Entry Subclass
--------------------------------

[](#custom-dictionary-entry-subclass)

For a dictionary with slug `service_family`, package resolves:

- `App\Models\DictionnaryEntry\ServiceFamily` (or your configured namespace)

Interface:

- `MetaFramework\Dictionnaries\Contracts\CustomDictionnaryInterface`

Example:

```
