t-labs-co / config-walker
A centralized configuration walker for Laravel — merge multiple config sources, tag-based scoping, and enum-aware config resolution.
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/contracts: ^12|^13
- illuminate/support: ^12|^13
Requires (Dev)
- larastan/larastan: ^3
- laravel/pint: ^1
- orchestra/testbench: ^10|^11
- pestphp/pest: ^4|^5
- pestphp/pest-plugin-arch: ^3|^4
- pestphp/pest-plugin-laravel: ^4|^5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.
Features
- 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
Requirements
| Package | Version |
|---|---|
| PHP | ^8.4 |
| Laravel | ^12 | ^13 |
Walkable Sources
| 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 |
Installation
composer require t-labs-co/config-walker
Upgrading 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"
Usage
With a Model
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');
With an Enum
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 name
With ConfigWalkerAware
Implement 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'; } }
Tags
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);
Helper Function
// Get the ConfigWalker instance config_walker(); // Get a config value config_walker('your-key'); // Set config values config_walker(['your-key' => 'your-value']);
Access Laravel Config
// 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');
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Upgrading from v1?
See the Migration Guide for step-by-step upgrade instructions.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
Quality
- PHPStan Level 8 — strict static analysis
- Pest PHP — comprehensive test suite
- Laravel Pint — code style enforcement
License
The MIT License (MIT). Please see License File for more information.