Organizing Configurations with Laravel's Config Repository #719
pronist
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Jigsaw's configuration is relatively easy since everything can be done in
config.php, but I wondered if we could manage it more cleanly by separating it, similar to Laravel.Installation
mkdir my-app cd my-app composer require tightenco/jigsaw vendor/bin/jigsaw init npm installWhen initializing Jigsaw, the default configuration looks like this:
Configuration
We can categorize the configuration into app settings like
production,baseUrl,title,description; collections likecollections; and additional page variables or helper functions. While managing helper functions inhelpers.phpworks well, what if we separated the other parts?Let's use Laravel Configuration to separate them.
Since we'll be adding a dedicated class for managing configurations, let's add PSR-4 settings to
composer.json.Config
Before creating the Configuration class, let's first create a
configdirectory and configuration files. We'll separate production-specific settings.config/app.php
config/collections.php
config/variables.php
config/production/app.php
Configuration
The
Configurationclass is a dedicated class for managing settings.In
Configuration, we use Laravel's Config Repository to manage the settings. We initialize the Repository for the settings, specify the path for the configuration files in the constructor, and load them withConfiguration::load(). TheConfiguration::getConfig()method is used inconfig.phpandconfig.production.phpto retrieve the merged settings from the Repository as an array.Now, simply use
Configuration::getConfig()inconfig.phpandconfig.production.php.config.php
config.production.php
Beta Was this translation helpful? Give feedback.
All reactions