{"id":17995639,"url":"https://github.com/skywarth/laravel-config-mapper","last_synced_at":"2026-05-09T10:07:18.716Z","repository":{"id":63253935,"uuid":"555021464","full_name":"skywarth/laravel-config-mapper","owner":"skywarth","description":"Easily generate env keys for your custom configs","archived":false,"fork":false,"pushed_at":"2023-01-02T20:21:51.000Z","size":114,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T17:21:27.482Z","etag":null,"topics":["composer","composer-library","composer-package","config-mapper","dotenv","environment-variables","laravel","laravel-config","laravel-env","laravel-environment","mapper","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skywarth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2022-10-20T20:13:44.000Z","updated_at":"2022-12-26T20:03:22.000Z","dependencies_parsed_at":"2023-02-01T04:01:09.825Z","dependency_job_id":null,"html_url":"https://github.com/skywarth/laravel-config-mapper","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2Flaravel-config-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2Flaravel-config-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2Flaravel-config-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2Flaravel-config-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skywarth","download_url":"https://codeload.github.com/skywarth/laravel-config-mapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247128737,"owners_count":20888234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","composer-library","composer-package","config-mapper","dotenv","environment-variables","laravel","laravel-config","laravel-env","laravel-environment","mapper","php"],"created_at":"2024-10-29T21:08:20.962Z","updated_at":"2026-05-09T10:07:13.653Z","avatar_url":"https://github.com/skywarth.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Code Coverage Badge](./badge.svg) \n\n*Proof reading for the documentation is pending*\n\n# Laravel Config Mapper\n\nPackagist: https://packagist.org/packages/skywarth/laravel-config-mapper\n\n## Table of Contents\n\n- [Installation](#installation) \n- [Problem Definition](#problem-definition)\n  - [Example case](#example-case)\n- [How to Use](#how-to-use)\n  - [TL;DR](#how-to-use-tl-dr)\n  - [Map the env keys by command](#map-env-keys-command)\n    - [Just output the mapped env keys](#map-env-keys-command-just-output)\n    - [Add mapped env keys to file](#map-env-keys-command-add-mapped-env-keys-to-file)\n    - [Update configs and replace](#map-env-keys-command-update-config)\n  - [Alternative Config Helper](#alternative-config-helper)\n- [Roadmap \u0026 TODOs](#roadmap-and-todos)\n- [Credits \u0026 References](#credits-and-references)\n\nLaravel Config Mapper is a package for assisting your project with the ability to **automatically map configs with env keys**. It is designed for Laravel framework.\n\n## \u003ca name='installation'\u003e\u003c/a\u003e Installation\n\nRun:\n```\ncomposer require skywarth/laravel-config-mapper\n```\n\nOptionally, you may publish the config, which allows you to tinker with libraries settings:\n```\nphp artisan vendor:publish --provider=\"Skywarth\\LaravelConfigMapper\\LaravelConfigMapperServiceProvider\" --tag=\"config\"\n```\n\n\n\n\n\n## \u003ca name='problem-definition'\u003e\u003c/a\u003e Problem Definition\n\nYou know the hassle... When defining a new configuration or adding to existing configuration, you have to give it a corresponding and appropriate env key. And if your config hierarchy has some depth, it is rather troublesome and prone to error. Laravel Config Mapper can help you eliminate this.\n\n### \u003ca name='example-case'\u003e\u003c/a\u003e Example Case\n    \n```\nyour-laravel-project/\n├── config/\n│   ├── filesystems.php\n│   ├── app.php\n│   ├── auth.php\n│   ├── queue.php\n│   ├── **tiger.php**\n│   ├── mammals/\n│   │   ├── panda.php\n│   │   ├── dog.php\n│   │   └── room/\n│   │       └── elephant.php\n│   └── non-mammals/\n│       └── penguin\n├── app\n├── storage\n├── public\n├── .env\n└── .env.example\n```\n\u003cp align=\"center\" name=\"example-folder-structure\"\u003e\u003ci\u003eExample folder structure\u003c/i\u003e\u003c/p\u003e\n\n\nFor the file structure above, assume you want to create configs for `tiger`, `panda`, `dog`, `elephant` and `penguin` (files are already created).\n\nIf we consider `elephant` in the `room` folder, and let's say we want elephant config to have `enabled`, and under `permissions` group `allowed_to_walk` and `allowed_to_sleep`. It would look something like this:\n```php\n#./config/mammals/room/elephant.php\n\u003c?php\nreturn [\n    'enabled'=\u003eenv('MAMMALS_ROOM_ELEPHANT_ENABLED',1),\n    'permissions'=\u003e[\n        'allowed_to_walk'=\u003eenv('MAMMALS_ROOM_ELEPHANT_PERMISSIONS_ALLOWED_TO_WALK',1),\n        'allowed_to_sleep'=\u003eenv('MAMMALS_ROOM_ELEPHANT_PERMISSIONS_ALLOWED_TO_SLEEP',1)\n    ]\n];\n```\n\nE.g: `config('mammals.room.elephant.permissions.allowed_to_walk')` for accessing\n\nAs you can see, it becomes cumbersome to name env keys after certain folder/path depth. If you ever had to deal with scenarios where you access a config like `config('some.really.deep.down.config.and.also.in.an.array.nice_key_though')` you know how painful it is to write the env key for that. \n\n\n\n## \u003ca name='how-to-use'\u003e\u003c/a\u003e How to use\n\nThere is two distinct application methods for this package:\n1. Map the env keys by command \n2. Alternative config helper\n\n### \u003ca name='how-to-use-tl-dr'\u003e\u003c/a\u003e TL;DR\n1. Put `'automap'` value for configs\n2. Run `php artisan laravel-config-mapper:publish-env-keys`\n\n### \u003ca name='map-env-keys-command'\u003e\u003c/a\u003e Map the env keys by command\n\nThis method is the recommended way of using this library.\n\n1. Put the value of `'automap'` for those configs that you'd like to map\n   1. e.g: \u003ca name='sample-application-of-automap'\u003e\u003c/a\u003eSample application of automap\n      ```php\n      #./config/mammals/room/elephant.php\n      \u003c?php\n        return [\n        'enabled'=\u003eenv('MAMMALS_ROOM_ELEPHANT_ENABLED',1),\n        'permissions'=\u003e[\n            'allowed_to_walk'=\u003e'automap' //NOTICE HERE\n            'allowed_to_sleep'=\u003eenv('MAMMALS_ROOM_ELEPHANT_PERMISSIONS_ALLOWED_TO_SLEEP',1)\n        ]\n      ];\n      ```\n2. Run the dedicated \u003ca name='publish-env-keys-command'\u003e\u003c/a\u003e command: `php artisan laravel-config-mapper:publish-env-keys`\n   1. It'll discover your automap configs\n   2. After discovery, it'll prepare respective env keys for these\n   3. Then config path \u0026 env key pairs will be output\n   4. So far no change is made at all to your codebase\n3. Select an option on how you'd like to apply\n   1. Each option is explained down below\n\n#### \u003ca name='map-env-keys-command-just-output'\u003e\u003c/a\u003e 1. \"Just output the mapped env keys, I'll copy them myself\"\nThis option will just output the env keys that you'll have to use. Just as the name suggests, it doesn't alter any file at all in your codebase.\nAfter receiving the output from the console, you should paste the mapped env keys to your `.env` or wherever you like. Then you should replace all `'automap'` values in config with an `env()` helper function call. \n\nFor the [example](#sample-application-of-automap) above, it would produce this output:\n```\n--------------COPY BELOW--------------\n#[AUTOMAP ENV KEYS BEGIN] - DON'T ALTER THIS LINE\nMAMMALS.ROOM.ELEPHANT.PERMISSIONS.ALLOWED_TO_WALK=\n#[AUTOMAP ENV KEYS END] - DON'T ALTER THIS LINE\n--------------COPY ABOVE--------------\nDon't forget to assign values to your env keys !\n\n```\n\n#### \u003ca name='map-env-keys-command-add-mapped-env-keys-to-file'\u003e\u003c/a\u003e 2. \"Add mapped env keys to file\"\n\nThis option will print the mapped env keys into a file of your choice.\nReturning to the [example](#sample-application-of-automap), when we run the [command](#publish-env-keys-command) and chose this option, and pick `.env` as our target file, we can observe the change in `.env` file:\n\n```\n#.env file\n\nAPP_NAME=Laravel\nAPP_ENV=local\nAPP_KEY=\nAPP_DEBUG=true\nAPP_URL=http://localhost\n\n\n#[AUTOMAP ENV KEYS BEGIN] - DON'T ALTER THIS LINE\nMAMMALS.ROOM.ELEPHANT.PERMISSIONS.ALLOWED_TO_WALK=\n#[AUTOMAP ENV KEYS END] - DON'T ALTER THIS LINE\n```\n\nIf automap env keys section present, the command will update the existing section. Otherwise it'll just append the section to the end of the file. \n\nYou can pick among these options as files:\n- .env\n- .env.example\n- laravel-config-mapper.env\n\nIf the chosen file doesn't exist, the command will ask you if you'd like it to be created.\n\n\n#### \u003ca name='map-env-keys-command-update-config'\u003e\u003c/a\u003e 3. \"Update configs to replace 'automap' values with corresponding env keys, then add mapped keys to file\"\n\nThis option allows you to be completely independent of config mapper library. It replaces any `'automap'` value placed in configs with appropriate mapped env keys. After that, it'll continue with the same procedure as [\"Add mapped env keys to file\"](#map-env-keys-command-add-mapped-env-keys-to-file). \n\nRecalling [example](#sample-application-of-automap), running [command](#publish-env-keys-command) with this choice will produce these changes:\n\n```php\n      #./config/mammals/room/elephant.php\n      \u003c?php\n        return [\n        'enabled'=\u003eenv('MAMMALS_ROOM_ELEPHANT_ENABLED',1),\n        'permissions'=\u003e[\n            'allowed_to_walk'=\u003eenv('MAMMALS.ROOM.ELEPHANT.PERMISSIONS.ALLOWED_TO_WALK','automap') //NOTICE HERE\n            'allowed_to_sleep'=\u003eenv('MAMMALS_ROOM_ELEPHANT_PERMISSIONS_ALLOWED_TO_SLEEP',1)\n        ]\n      ];\n```\nSee the `'allowed_to_walk'` key, it had the value of `'automap'` prior to running the command, but now it is paired to an env key.\n\nAnd corresponding mapped env keys are added to `.env` file, how convenient. \n\n```\n#.env file\n\n#[AUTOMAP ENV KEYS BEGIN] - DON'T ALTER THIS LINE\nMAMMALS.ROOM.ELEPHANT.PERMISSIONS.ALLOWED_TO_WALK=\n#[AUTOMAP ENV KEYS END] - DON'T ALTER THIS LINE\n```\n\n\n---\n\n### \u003ca name='alternative-config-helper'\u003e\u003c/a\u003e Alternative Config Helper\n\nThis method is not the recommended method. Please advise [Map the env keys by command](#map-env-keys-command) method to see if it fits your needs.\n\nPackage ships with a new helper function at your disposal. Let's return to the `elephant` config. But this time we'll be using Laravel Config Mapper's helper function `configMapped()`.\n\n```php\n#./config/mammals/room/elephant.php\n\u003c?php\nreturn [\n    'enabled'=\u003e'automap',\n    'permissions'=\u003e[\n        'allowed_to_walk'=\u003e'automap',\n        'allowed_to_sleep'=\u003eenv('MAMMALS_ROOM_ELEPHANT_PERMISSIONS_ALLOWED_TO_SLEEP',1)\n    ]\n];\n```\nYou may have noticed that `enabled` and `allowed_to_walk` configs have the value of `'automap'`. This is due to the fact we are feeling lazy and don't want to ponder about some env key for it.\n\nNow run `php artisan laravel-config-mapper:publish-env-keys` command. In the command, when we select '[1] Just output the mapped env keys, I'll copy them myself' option, it outputs this:\n```\n4. Copy this and paste it to your env, then edit values as you wish:\n--------------COPY BELOW--------------\n#[AUTOMAP ENV KEYS BEGIN] - DON'T ALTER THIS LINE\nMAMMALS.ROOM.ELEPHANT.ENABLED=\nMAMMALS.ROOM.ELEPHANT.PERMISSIONS.ALLOWED_TO_WALK=\n#[AUTOMAP ENV KEYS END] - DON'T ALTER THIS LINE\n--------------COPY ABOVE--------------\n```\nMarvelous, now we can just copy this string and paste it into `.env` file. After pasting it and assigning values, only one thing left to do: use the `configMapped()` instead of `config()`. Because if you use `config('mammals.room.elephant.permissions.allowed_to_walk')`, it'll give you `'automap'` naturally. But if you use `configMapped('mammals.room.elephant.permissions.allowed_to_walk')` It'll automatically find the corresponding env key *(MAMMALS.ROOM.ELEPHANT.PERMISSIONS.ALLOWED_TO_WALK)* and return Its value. \n\n**Q:** *hurrr durr why do I have to use an alternate config helper ?? How am I supposed to know when to use config() and when to use configMapped()*\n\n**A:** It is better to always use `configMapped()` because it inherently calls `config() ` inside anyways if the corresponding config doesn't have `'automap'` value. In other terms, it is just a wrapper around config helper to grant it additional capabilities. For the example above, I can still access `allowed_to_sleep` config using `configMapped()` even though it is not an automap config.  \n\n\n\n## \u003ca name='roadmap-and-todos'\u003e\u003c/a\u003e Roadmap \u0026 TODOs\n\n- [X] ~~Table of content for readme~~\n- [X] ~~Assigned values for mapped env keys are lost when written :( Gotta find a way to preserve it~~\n- [X] ~~Refactor the command~~\n- [X] ~~Make helper function registration optional through config~~\n- [X] ~~Unit tests~~\n- [X] ~~Code coverage~~\n- [X] ~~comment blocks for config file~~\n- [ ] Optionally remove redundant keywords from mapped env key. \n- [X] ~~Don't allow those keys that are not valid for dotenv files (*,-,|,@,#,(,)),/,?,[,],`,`, etc.. Welp, **basically anything other than** [alphanumeric, `_` and `.`] is not accepted.)~~\n\n\n\n## \u003ca name='credits-and-references'\u003e\u003c/a\u003e Credits \u0026 References\n\nThis project has been developed using JetBrains products. \nThanks for their [support for open-source development](https://www.jetbrains.com/community/opensource/#support).\n\n\n| \u003cimg width=\"150\" src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg\" alt=\"JetBrains Logo (Main) logo.\"\u003e | \u003cimg width=\"200\" src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/PhpStorm.svg\" alt=\"PhpStorm logo.\"\u003e |\n|--------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskywarth%2Flaravel-config-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskywarth%2Flaravel-config-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskywarth%2Flaravel-config-mapper/lists"}