PHPackages                             inclus16/laravel-dictionary - 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. [Caching](/categories/caching)
4. /
5. inclus16/laravel-dictionary

ActiveLibrary[Caching](/categories/caching)

inclus16/laravel-dictionary
===========================

Provide cached collection-based data in laravel

v1.0.1(1mo ago)01MITPHPPHP ^8.5CI passing

Since Jul 9Pushed 1mo agoCompare

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

READMEChangelog (2)Dependencies (8)Versions (6)Used By (0)

Laravel dictionary
==================

[](#laravel-dictionary)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0e35fb7e9352ba558c6a6ef14192a85de66f4b508b05cda74fbb532fa054ef1a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e636c757331362f6c61726176656c2d64696374696f6e6172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/inclus16/laravel-dictionaru)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/d54292535da49cd3eb7d247a8eb54c17280bb24e25cff31301bc6fefc0c39953/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e636c757331362f6c61726176656c2d64696374696f6e6172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/inclus16/laravel-dictionary)

Laravel dictionary is a package, that manages access, validation and cache for your collection-based data.

A dictionary is a static (or nearly static) set of data that needs to be reread very often.

Prerequirements
---------------

[](#prerequirements)

PHP &gt;= 8.5

Laravel &gt;=13

Install
-------

[](#install)

```
composer require inclus16/laravel-dictionary:v1.0.0
```

The package will automatically register a service provider Publish the package's configuration and translations by running:

```
php artisan vendor:publish --provider="Inclus16\LaravelDictionary\DictionaryServiceProvider"
```

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

[](#configuration)

In .env file there constants that can be added:

DICTIONARY\_DEFAULT\_CACHE\_STORE - see Laravel cache (default: array)

DICTIONARY\_DEFAULT\_CACHE\_TTL - see Laravel cache (default: 3600)

Usage
-----

[](#usage)

The main class that you may work with is some classes that may be called DictionaryHandler.

```
class PageType extends \Inclus16\LaravelDictionary\Handlers\AbstractDictionaryHandler
{
    /**
    * Use this slug for access this handler in validation, http, files, or in your code.
    * @return string
     */
    public static function getSlug() : string{
        return 'page_types';
    }
}
```

This class must be registered in config dictionary.php:

```
return [
    'default_cache_store' => env('DICTIONARY_DEFAULT_CACHE_STORE', 'array'),
    'default_cache_ttl' => env('DICTIONARY_DEFAULT_CACHE_TTL', 3600),
    'handlers' => [
        PageType::getSlug() => PageType::class
    ],
    'publishDisk' => 'public'
];
```

Full methods of AbstractDictionaryHandler that can be extended:

```
abstract class AbstractDictionaryHandler implements DictionaryHandlerInterface
{

    /**
     * What response class must be used
     * @return string
     */
    protected function getResponseEntityClass(): string
    {
        return SimpleEntityResponse::class;
    }

    /**
     * What cache store must be used (see Laravel cache)
     * @return bool
     */
    protected function getCacheStore(): Repository
    {
        return Cache::store(Config::string('dictionary.default_cache_store'));
    }

    /**
     * How many times cache should live (see Laravel cache)
     * @return bool
     */
    protected function getCacheTtl(): int
    {
        return Config::integer('dictionary.default_cache_ttl');
    }

    /**
     * This method called only when http access happens.
     * @return bool
     */
    public function authorize(): bool
    {
        return Auth::check();
    }

    /**
     * Whenever this dictionary must be stored on disk as json file. If so nginx can handle it directly. For optimization purpose for most times
     * @return bool
     */
    public function toPublish(): bool
    {
        return true;
    }

    /**
     * Main method you must implement. How DictionaryHandler will fetch fresh, uncached data (from database as example)
     * @return Collection
     */
    protected abstract function fetchUncachedEntities(): Collection;

    /**
     * Usually used in code
     * @return Collection
     */
    public function getEntities(): Collection
    {
        return $this->getCacheStore()->remember($this->getSlug(), $this->getCacheTtl(), fn() => $this->fetchUncachedEntities());
    }

    /**
     * Forget cached data from cache. Useful when your dictionary data was updated (database insert/update)
     * @return void
     */
    public function clearCache(): void
    {
        $this->getCacheStore()->forget($this->getSlug());
    }

    /**
     * Used only in http access. If null - no http response headers will be added. If not null - will add header Cache-Control: public, max-age={x}
     * @return int|null
     */
    public function getResponseCacheSeconds(): ?int
    {
        return 604800;//one week
    }

    /**
     *  Transforms cached collection of entities to collection of response entities
     * @return Collection
     */
    public function getResponseEntities(): Collection
    {
        $responseEntityClass = $this->getResponseEntityClass();
        return $this->getEntities()->map(fn(mixed $entity) => new $responseEntityClass($entity));
    }
}
```

### Validation

[](#validation)

For validation, you may use one of two rules:

```
'fieldFromRequest' => [new InDictionary(string $slug, string $field)]
```

This rule will search in dictionary {slug}, iterates over cached entities and compare value from request with {field} value from entity. If entity with equality will found - validation will be passed

```
'fieldFromRequest' => [new  NotInDictionary(string $slug, string $field)]
```

This rule will search in dictionary {slug}, iterates over cached entities and compare value from request with {field} value from entity. If entity with equality does NOT found - validation will be passed

### Access in code

[](#access-in-code)

#### Facade

[](#facade)

```
\Inclus16\LaravelDictionary\Facade\Dictionary::getHandler(string $slug)
```

Just one method. This will return a dictionary handler with this {slug}, or throw OutOfRangeException

#### DI

[](#di)

Inject \\Inclus16\\LaravelDictionary\\Handler\\HandlerFactory class

### Static files

[](#static-files)

For optimization purposes you may call

```
php artisan dictionaries:publish
```

this command with create json files that contains data of dictionary. for each dictionary there will be created a file, named {dictionarySlug}.json in disk from config: dictionary.publishDisk. Then you can handle this files directly via nginx as static files

### Http access

[](#http-access)

```
GET /api/dictionary/{slug}
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

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

Every ~0 days

Total

4

Last Release

47d ago

### Community

Maintainers

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

---

Top Contributors

[![inclus16](https://avatars.githubusercontent.com/u/39311013?v=4)](https://github.com/inclus16 "inclus16 (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/inclus16-laravel-dictionary/health.svg)

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

###  Alternatives

[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

80427.1M249](/packages/laravel-mcp)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k2](/packages/mike-bronner-laravel-model-caching)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M147](/packages/roots-acorn)[propaganistas/laravel-disposable-email

Disposable email validator

6023.2M7](/packages/propaganistas-laravel-disposable-email)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

265.2k](/packages/aedart-athenaeum)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)

PHPackages © 2026

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