PHPackages                             iak/keys - 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. iak/keys

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

iak/keys
========

This is my package keys

v1.0.0(8mo ago)4152[3 PRs](https://github.com/iaK/keys/pulls)MITPHPPHP ^8.3CI passing

Since Oct 16Pushed 2mo agoCompare

[ Source](https://github.com/iaK/keys)[ Packagist](https://packagist.org/packages/iak/keys)[ Docs](https://github.com/iak/keys)[ GitHub Sponsors](https://github.com/Iak)[ RSS](/packages/iak-keys/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (12)Versions (6)Used By (0)

Laravel Keys 🔑
==============

[](#laravel-keys-)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6c4002da06e143bfb0dc023b31ae580b2a4df99bfbb852e6d4dce41ec7283f1a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69616b2f6b6579732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iak/keys)[![GitHub Tests Action Status](https://camo.githubusercontent.com/88c2429d899f4fb24f8b94c909a1bba5561f0f5029ba29d6ecf80de7e43d4499/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f69616b2f6b6579732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/iak/keys/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/54c950050f206241d2ad4c9bb804eec59237c0fc2bda9d248bbb3c0f926704c4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f69616b2f6b6579732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/iak/keys/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/ac6e823761dd0c3e61c73c09e243eb48bc4fa18c9b441a5e48f28397d83c579f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69616b2f6b6579732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iak/keys)

The problem
-----------

[](#the-problem)

We use string keys all across our application. We got keys for cache, rate limiting, queued jobs, sessions, broadcast channels, container aliases and so much more.

These keys can be hard to keep track of. You also need to remember what convention you used, sometimes build up keys from several dynamic values such as id's, and it's hard to get an overview of what keys are actually in use. It's also easy for typos to sneak in, as these are just strings.

This package solves this issue, by centralizing where your keys are defined, and give you a consistent and easy way to access them.

Features
--------

[](#features)

- **Configurable Key Templates**: Define key formats in configuration files
- **Dynamic Parameters**: Define your dynamic values in the configuration, and the key class will fill them in for you
- **Parameter Validation**: Automatic validation of required parameters and detection of extra parameters
- **Multiple Key Types**: Built-in support for cache, queue, event, session, and many more key types
- **Laravel Integration**: Seamless integration with Laravel's configuration system

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

[](#installation)

You can install the package via composer:

```
composer require iak/keys
```

Then publish the config file with:

```
php artisan vendor:publish --tag="keys-config"
```

Usage
-----

[](#usage)

First, define your key templates in the configuration file:

```
// config/keys.php
return [
    'cache' => [
        'product-data' => 'product:{productId},variant:{variantId}',
    ],
    'limit' => [
        'password-reset' => 'password-reset:{userId}'
    ]
];
```

Then access the keys using the Key helper class.

```
use Iak\Key\Key;

// Using named parameters
Key::cache('product-data', productId: 123, variantId: 456);

// Using array parameters
Key::cache('product-data', [
    'productId' => 123,
    'variantId' => 456
]);

// Using parameter position
Key::cache('user.action', 123, 456);

// The result for all above: "product:123,variant:456"
```

### Built-in Key Types

[](#built-in-key-types)

The package comes with many built-in key types:

```
// Cache keys
Key::cache('user.profile', id: 123);

// Queue keys
Key::queue('email.notification', type: 'welcome', userId: 456);

// Event keys
Key::event('user.action', action: 'login', userId: 789);

// Session keys
Key::session('user.data', userId: 123, sessionId: 'abc123');

// Job keys
Key::job('process.data', jobType: 'import', priority: 'high');

// Lock keys
Key::lock('', version: 'v1', resource: 'users');
```

There are support for many different types of keys. For example: tag, lock, channel, broadcast, limit, middleware, view, translation, command, container, feature, notification, throttle, disk, policy, guard, schedule, tenant, experiment, test, mail, service, flash, alias, provider, raw, config

### Dynamic Method Calling

[](#dynamic-method-calling)

You can also use dynamic method calling for custom key types:

```
// Define a custom key type in config
// config/keys.php
return [
    'custom' => [
        'api.request' => 'api:{endpoint}:{method}:{timestamp}',
    ],
];

// Use it dynamically
$key = Key::custom('api.request',
    endpoint: 'users',
    method: 'GET',
    timestamp: time()
);
// Result: "api:users:GET:1234567890"
```

### Error Handling

[](#error-handling)

The package validates parameters and provides helpful error messages:

```
// Missing required parameter
Key::cache('user.profile');
// Throws: Missing required parameters: id

// Extra parameter not in template
Key::cache('user.profile', id: 123, extra: 'value'); // Throws: Extra parameters: extra

// Non-existent key
Key::cache('nonexistent.key', id: 123); // Throws: Key not found in config
```

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

[](#configuration)

### Key Template Format

[](#key-template-format)

Key templates use curly braces `{}` to define parameter placeholders:

```
'user.profile' => 'user:profile:{id}',
'product.details' => 'product:{category}:{id}:{variant}',
'api.request' => 'api:{version}:{endpoint}:{method}',
```

### Parameter Rules

[](#parameter-rules)

- All parameters defined in the template must be provided
- Extra parameters not defined in the template will cause an exception
- The same parameter can be used multiple times in a template
- Parameters can be strings, numbers, or any scalar value

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Isak Berglind](https://github.com/iaK)
- [Erik Bäck](https://github.com/erback)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance74

Regular maintenance activity

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

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

259d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f8e167637ace3c09cf95c25f7d826a2352f06a7bd47d512f2ee5ed484840a27?d=identicon)[iaK](/maintainers/iaK)

---

Top Contributors

[![iaK](https://avatars.githubusercontent.com/u/2571644?v=4)](https://github.com/iaK "iaK (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelkeys

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/iak-keys/health.svg)

```
[![Health](https://phpackages.com/badges/iak-keys/health.svg)](https://phpackages.com/packages/iak-keys)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)[tapp/filament-form-builder

User facing form builder using Filament components

132.4k3](/packages/tapp-filament-form-builder)

PHPackages © 2026

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