A centralized configuration walker for Laravel — merge multiple config sources, tag-based scoping, and enum-aware config resolution.
Centralize data from database tables, enums, constants, arrays, and settings into a single organized hub. Avoid copy-paste and keep your config clean.
- Centralize different config sources into a single hub
- Support for database tables, enums, constants, hard-coded arrays, and settings
- Tag-based config scoping and merging
- Easy integration with Laravel models and enums via traits
- Helper function
config_walker()for quick access - Auto-load with Laravel's config system
| Package | Version |
|---|---|
| PHP | ^8.4 |
| Laravel | ^12 | ^13 |
| Source Type | Trait / Interface | Description |
|---|---|---|
| Eloquent Model | ConfigWalkable |
Export model data via walkable() |
| Backed Enum | EnumConfigWalkable |
Auto-export enum values |
| Custom Object | Contracts\ConfigWalkerAware |
Implement toWalker() and walkerKey() |
| Array | — | Pass arrays directly to walk() |
| Laravel Config | — | Use 'default' walker to load app config |
composer require t-labs-co/config-walkerUpgrading from v1.x? Read the Migration Guide for a step-by-step upgrade path.
Publish the config file:
php artisan vendor:publish --tag="config-walker-config"Use the ConfigWalkable trait on your model:
use TLabsCo\ConfigWalker\ConfigWalkable;
class Category extends Model
{
use HasFactory, ConfigWalkable;
public function walkable(): array
{
return self::query()
->pluck('name', 'slug')
->toArray();
}
public function walkerKey(): string
{
return 'categories';
}
}Then walk the model:
use TLabsCo\ConfigWalker\Facades\ConfigWalker;
ConfigWalker::walk(Category::class);
ConfigWalker::get('categories');Use the EnumConfigWalkable trait:
use TLabsCo\ConfigWalker\EnumConfigWalkable;
enum CategoryType: string
{
use EnumConfigWalkable;
case Post = 'post';
case Product = 'product';
case Book = 'book';
}ConfigWalker::walk(CategoryType::class);
ConfigWalker::get('category_type'); // key is auto-generated from enum nameImplement the Contracts\ConfigWalkerAware interface:
use TLabsCo\ConfigWalker\Contracts\ConfigWalkerAware;
class MyConfigSource implements ConfigWalkerAware
{
public function toWalker(): array
{
return ['key' => 'value'];
}
public function walkerKey(): string
{
return 'my_source';
}
}Group configs under tags for scoped retrieval:
ConfigWalker::walk(['a' => 1], null, 'group1');
ConfigWalker::walk(['b' => 2], null, 'group2');
// Get a single tag's config
ConfigWalker::tag('group1')->get('a');
// Merge multiple tags
ConfigWalker::tags(['group1', 'group2']);
// Flat merge
ConfigWalker::tags(['group1', 'group2'], flat: true);// Get the ConfigWalker instance
config_walker();
// Get a config value
config_walker('your-key');
// Set config values
config_walker(['your-key' => 'your-value']);// Load Laravel's app config into ConfigWalker
ConfigWalker::loadDefault();
// Or set in config/config-walker.php:
// 'loadWithAppConfig' => true
// Access via ConfigWalker
ConfigWalker::makeDefault()->get('app.name');composer testPlease see CHANGELOG for more information on what has changed recently.
See the Migration Guide for step-by-step upgrade instructions.
Please review our security policy on how to report security vulnerabilities.
- PHPStan Level 8 — strict static analysis
- Pest PHP — comprehensive test suite
- Laravel Pint — code style enforcement
The MIT License (MIT). Please see License File for more information.