Laravel Config Walker

Centralized configuration hub for Laravel

2.0.0 GitHub ActionsMITPHP ^8.4Laravel ^12.0 | ^13.0

Pull data from database tables, enums, constants, hard-coded arrays, and settings into a single, organized config hub. Tag-based scoping, enum-aware resolution, and helper function for quick access.

Requirements

Core Package
  • PHP ^8.4
  • Laravel ^12.0 | ^13.0

Install with Composer

composer require t-labs-co/config-walker

Get started in minutes

1. Install the package

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"

2. Walk an Eloquent 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');

3. Walk 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

4. Walk custom objects

Implement the 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';
    }
}

5. Use tags for scoped config

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']);

6. Helper function

// Get a config value
config_walker('your-key');

// Set config values
config_walker(['your-key' => 'your-value']);

Features

Walkable sources

Source Type Trait / Interface Description
Eloquent Model ConfigWalkable Export model data via walkable()
Backed Enum EnumConfigWalkable Auto-export enum values
Custom Object ConfigWalkerAware Implement toWalker() and walkerKey()
Array — Pass arrays directly to walk()
Laravel Config — Use 'default' walker to load app config

Tag-based scoping

Group configs under tags for selective loading and merging. Retrieve a single tag’s config or merge multiple tags with flat or nested options.

Access Laravel config

Load Laravel’s app config into ConfigWalker:

ConfigWalker::loadDefault();
ConfigWalker::makeDefault()->get('app.name');

Or set 'loadWithAppConfig' => true in config/config-walker.php.

For complete documentation, see the README on GitHub.

Hire me for Laravel configuration and architecture work

Need a package tailored to your application? From recurring Laravel maintenance tasks to reusable components, I can help design, build, and review production-ready solutions.

Discuss your project