Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Config Laravel Package

league/config

Define and validate nested PHP configuration with strict schemas (via Nette Schema). Merge multiple config sources, apply defaults, enforce types/constraints, and read values using convenient dot notation. Ideal for robust, structured app and library config.

View on GitHub
Deep Wiki
Context7

layout: default title: Setting User-Provided Values description: How to apply user-provided values against the configuration schema

Setting User-Provided Values

Once your schema has been defined you can apply user-provided configuration values. There are two methods available to do this:

  • set($key, $value) - Define a single value
  • merge($values) - Define multiple values in one call

Example

Let's take the following configuration as an example:

use League\Config\Configuration;
use Nette\Schema\Expect;

$config = new Configuration([
    'debug_mode' => Expect::bool()->required(),
    'database' => Expect::structure([
        'driver' => Expect::anyOf('mysql', 'postgresql', 'sqlite')->required(),
        'host' => Expect::string()->default('localhost'),
        'port' => Expect::int()->min(1)->max(65535),
        'ssl' => Expect::bool(),
        'database' => Expect::string()->required(),
        'username' => Expect::string()->required(),
        'password' => Expect::string()->nullable(),
    ]),
    'logging' => Expect::structure([
        'enabled' => Expect::bool()->default($_ENV['DEBUG'] == true),
        'file' => Expect::string()->deprecated("use logging.path instead"),
        'path' => Expect::string()->assert(function ($path) { return \is_writeable($path); })->required(),
    ]),
]);

You could set everything at once like this:

$config->merge([
    'debug_mode' => false,
    'database' => [
        'driver' => 'mysql',
        'port' => 3306,
        'database' => 'myapp',
        'username' => 'myapp_user',
        'password' => 'hunter2',
    ],
    'logging' => [
        'enabled' => true,
        'file' => '/var/log/myapp.log',
    ],
]);

Maybe that array of data comes from a different file or method:

$config->merge(getUserConfig());

// or

$config->merge(json_decode(file_get_contents('database.json'), true));

Options can also be set individually, if needed:

// Load config from a json file...
$config->merge(json_decode(file_get_contents('database.json'), true));
// But override a certain setting
$config->set('debug_mode', false);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme